Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a java program to explain method overriding and avoid it by super keyword
- class ParentClass
- {
- int a = 10;
- ParentClass()
- {
- System.out.println("Constructor Of Parent");
- }
- void Disp()
- {
- System.out.println("Parent Method");
- }
- }
- // JavaExample is FileName
- class JavaExample extends ParentClass
- {
- int a = 20;
- JavaExample()
- {
- System.out.println("Constructor of Child");
- }
- void Disp()
- {
- System.out.println("Child Mathod");
- System.out.println(a);
- super.Disp();
- System.out.println(super.a);
- }
- public static void main(String args[])
- {
- JavaExample obj = new JavaExample();
- obj.Disp();
- }
- }
Add Comment
Please, Sign In to add comment