Tech World
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How the Super Class Constructor works in Sub Class?

Go down

How the Super Class Constructor works in Sub Class? Empty How the Super Class Constructor works in Sub Class?

Post by Admin Tue Mar 15, 2016 3:54 pm

When inheriting a Super Class, what happens to it's constructor?

Admin
Admin

Posts : 3
Join date : 2016-03-15

https://spnhub.board-directory.net

Back to top Go down

How the Super Class Constructor works in Sub Class? Empty Re: How the Super Class Constructor works in Sub Class?

Post by Admin Tue Mar 15, 2016 4:01 pm

When a class is inherited, all the members of the class are inherited EXCEPT for the constructor because the BASIC rule of a constructor is that it needs to have same name as class name.

Ex: Public Class Car()
{
//Constructor
Public Car();
}

Public Class Toyota extends Car()
{
Public Toyota();
}

You can now say
Toyota tycar = new Toyota();

But NOT
Toyota tycar = new Car();

Admin
Admin

Posts : 3
Join date : 2016-03-15

https://spnhub.board-directory.net

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum