A. t.m1();
Incase you're wondering why we couldn't access m3 even though it's protected and protected methods can be accessed in different package with subclass - " The protected members are inherited by the child classes and can access them as its own members. But we can’t access these members using the reference of the parent class. We can access protected members only by using child class reference."
package root;
public class Tree {
public void m1(){}
private void m2(){}
protected void m3(){}
void m4(){}
}
------------------------------------------------------------------
package branch;
import root.Tree;
public class Plant extends Tree{
public void m1(){}
public void m2(){}
public void m3(){}
public void m4(){}
public static void main(String[] args){
Tree t = new Plant();
t.m1();
// t.m2();
// t.m3();
// t.m4();
}
}
Because t is belong to Tree class
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
MPignaProTech
2 months agoDriftKing
1 year, 3 months agoDriftKing
1 year, 3 months agojackymak
1 year, 5 months ago