How the Super Class Constructor works in Sub Class?
Page 1 of 1
How the Super Class Constructor works in Sub Class?
When inheriting a Super Class, what happens to it's constructor?
Re: How the Super Class Constructor works in Sub Class?
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();
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();
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum