Inheritance can be fun, especially if you get loads of money. But then again Inheritance can be a big headache. Especially in Java, if you inherit more that you can chew…
package com.twisters;Got an answer? Why don’t you leave it here.
class Base{
public void baseCall(){
test();
}
public void test(){
System.out.println("Function Test in Base Executed");
}
}
public class Child extends Base {
public static void main(String[] args) {
Base baseRef = new Child ();
baseRef.baseCall();
}
public void test(){
System.out.println("Function Test in Child Executed");
}
}
Function Test in Child Executed
ReplyDeleteoverriden method takes precedence.
when child overrides parent method, the child method takes precedence.
ReplyDeleteFunction Test in Child Executed
ReplyDeleteFunction Test in Base Executed
Function Test in Child Executed
ReplyDeleteFunction Test in Child Executed
ReplyDeleteObject of Child Class Can not see the BaseClass Test Method
Function Test in Child Executed
ReplyDelete