How the Super Class Constructor works in Sub Class?

Go down

How the Super Class Constructor works in Sub Class?

Post by Admin on 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

View user profile http://spnhub.board-directory.net

Back to top Go down

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

Post by Admin on 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

View user profile http://spnhub.board-directory.net

Back to top Go down

Back to top


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