LETS SOLVE THIS QUERRY BY A PROGRAM..
PROGRAM:-
class X
{
void show()
{
System.out.println("Hello,Java I am inherited");
}
}
class Y extends X
{
}
class Demo
{
public static void main(String args[])
{
Y a=new Y();
a.show();
}
}
Output:-
Hello,Java I am inherited.
Note :- X is a super class and Y is a child class and extends is a keyword.
- Super Keyword :- used inside the child class to access the super class instance variable.
There is some restrictions which I have mentioned below..
Restriction:- The first statement inside the child class constructor must be super, otherwise it will give a compile time error.
Program:-
class X
{
voud show()
{
System.out.println("Hello");
}
}
class Y extends X
{
}
Class Z extends Y
{
z()
{
super.show();
}
}
Public class Demo extends Z
{
public static void main(String args[])
{
Z obj=new z();
}
}
Output:-
Hello
No comments:
Post a Comment