- Inheritance
- Constructors (default and argumented constructors)
- Sequence of constructors called when inheritance is involved.
- Using the super() to access the immediate super-class.
- How to call argumented constructor of any class.
SOURCE CODE:-
/********************************************************************************/
class basic_inheritance {
public static void main(String[] args) {
derived_class obj =new derived_class(90,80,70,60);
System.out.println(obj.a+" "+obj.b+" "+obj.c+" "+obj.d+" ");
}
}
class base_class {
int a,b;
base_class()
{
System.out.println("YOU ARE IN THE DEFAULT CONSTRUCTOR OF BASE_CLASS");
}
base_class(int p,int q)
{
a=p;
b=q;
System.out.println("YOU ARE IN THE ARGUMENTED CONSTRUCTOR OF BASE_CLASS");
}
}
class derived_class extends base_class{
int c,d;
derived_class()
{
System.out.println("YOU ARE IN THE DEFAULT CONSTRUCTOR OF DERIVED_CLASS");
}
derived_class(int p,int q,int r, int s)
{
super(p,q); //the keyword super is used to refer the immediate super class
c=r;
d=s;
System.out.println("YOU ARE IN THE ARGUMENTED CONSTRUCTOR OF DERIVED_CLASS");
}
}
/*******************************************************************************/
No comments:
Post a Comment