Virajsinh

Java_16

Feb 15th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. //Write a java program to explain method overriding and avoid it by super keyword
  2.  
  3. class ParentClass
  4. {
  5.     int a = 10;
  6.     ParentClass()
  7.     {
  8.         System.out.println("Constructor Of Parent");
  9.     }
  10.    
  11.     void Disp()
  12.     {
  13.         System.out.println("Parent Method");
  14.     }
  15.    
  16. }
  17.  
  18. // JavaExample is FileName
  19.  
  20. class JavaExample extends ParentClass
  21. {
  22.     int a = 20;
  23.     JavaExample()
  24.     {
  25.         System.out.println("Constructor of Child");
  26.     }
  27.    
  28.     void Disp()
  29.     {
  30.         System.out.println("Child Mathod");
  31.         System.out.println(a);
  32.        
  33.         super.Disp();
  34.         System.out.println(super.a);
  35.     }
  36.    
  37.     public static void main(String args[])
  38.     {
  39.         JavaExample obj = new JavaExample();
  40.         obj.Disp();
  41.     }
  42. }
Add Comment
Please, Sign In to add comment