Write a program in Java in which a subclass constructor invokes the constructor of the super class and instantiate the values

 

AIM: Write a program in Java in which a subclass constructor invokes the constructor of the superclass and instantiate the values

CODE:

class ahm extends Guj{

            String o;

            ahm(String o){

                        this.o=o;

                        System.out.print(o);

            }

}

class home extends ahm{

            String h;

            home(String h){

                        super("\nAhmedabad-->");

                        this.h=h;

                        System.out.print(h);

            }

}

class num extends home{

            num(String n){

                        super("Surabhi Residency,Nikol-->");

                        System.out.println(n);

            }

}

public class p21{

            public static void main(String args[]){

                        System.out.println("\nHome Address");

                        num obj=new num("C-203");

                       

            }

}                     

OUTPUT:



Comments

Popular posts from this blog

Write an application that illustrates method overriding in the same package and different packages. Also demonstrate accessibility rules in inside and outside packages

Describe abstract class called Shape which has three subclasses say Triangle, Rectangle, and Circle. Define one method area()in the abstract class and override this area() in these three subclasses to calculate for specific object.

Write a program in Java to perform I/O operations on a Text file.