Advertisement
MrPinzon

superExample.java

Feb 18th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. //Java program to illustrate Super keyword to refer parameterised constructor in parent class
  2.  
  3. //parent class
  4. class A
  5. {
  6.     //constructor of parent class
  7.     A()
  8.     {
  9.         System.out.println("I am inside class A.");
  10.     }
  11.     //parameterised constructor
  12.     A(String nameOfClass)
  13.     {
  14.         System.out.println("This is accessed from class " + nameOfClass);
  15.     }
  16. }
  17.  
  18. //child class
  19. class B extends A
  20. {
  21.     //constructor of child class
  22.     B()
  23.     {
  24.         super("B");
  25.         System.out.println("I am inside class B.");
  26.     }
  27. }
  28.  
  29. //main class
  30. public class superExample
  31. {
  32.     public static void main(String[] args)
  33.     {
  34.         System.out.println("I am inside superExample class.");
  35.         B objb = new B();//object of child class
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement