Deriving the base class property to child class. In java we using the keyword extends.
<modifier> class baseclassname extends childclassname
Example
class First
{
int a;
First()
{
a=5;
System.out.println("From class First's constructor ...");
}
void hai()
{
System.out.println("From class First , a = " + a);
}
}
class Inheritance extends First
{
Inheritance()
{
super(); //calling the base class constructor.
}
public static void main(String args[])
{
int a=5;
First f = new First();
f.hai();
System.out.println("From class Inheritance , a = " + 5);
}
}
Post a Comment