How the Super Class Constructor works in Sub Class?

View previous topic View next topic 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.forumotion.com

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.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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