AIM: Write a program in Java in which a subclass constructor invokes the constructor of the super class and instantiate the values.
MainClass.java
Output
Happy Coding :)
MainClass.java
class SuperClass { int x; SuperClass(int a) { x=a; System.out.println("Super Class : " +x); } } class SubClass extends SuperClass { int y; SubClass(int l,int m) { super(l); y=m; System.out.println("Sub class : "+y); } } class MainClass { public static void main(String arg[]) { SubClass s=new SubClass(5,4); } }
Output
subclass constructor invokes the constructor of the super class and instantiate the values in java by practical server |
Happy Coding :)
0 Comments
Post a Comment