Here Program we create a one sub class object and call four constructor mean Parameterized constructor and Without Parameterized constructor both class.
CODING:class a{
a(){
System.out.println("Parent A Class");
}
a(int a){
this();
System.out.println("Prent A class with argument");
}
}
class b extends a{
b(){
super(1);
System.out.println("Parent B Class");
}
b(int a){
this();
System.out.println("Prent B class with argument");
}
}
class demo{
public static void main(String[] args) {
b obj=new b(1);
}
}
/*OUTPUT:
Parent A Class
Prent A class with argument
Parent B Class
Prent B class with argument*/
a(){
System.out.println("Parent A Class");
}
a(int a){
this();
System.out.println("Prent A class with argument");
}
}
class b extends a{
b(){
super(1);
System.out.println("Parent B Class");
}
b(int a){
this();
System.out.println("Prent B class with argument");
}
}
class demo{
public static void main(String[] args) {
b obj=new b(1);
}
}
/*OUTPUT:
Parent A Class
Prent A class with argument
Parent B Class
Prent B class with argument*/
Comments
Post a Comment