Accessing MethodsWhich of the following statement(s) is(are) correct?(Note that more than one option may be correct.)An object of a superclass can access the public methods of the same superclass (itself).An object of a subclass can access the public methods of the same subclass (itself).An object of a superclass can access the public methods of its subclass.An object of a subclass can access the public methods of its superclass.
Question
Accessing MethodsWhich of the following statement(s) is(are) correct?(Note that more than one option may be correct.)An object of a superclass can access the public methods of the same superclass (itself).An object of a subclass can access the public methods of the same subclass (itself).An object of a superclass can access the public methods of its subclass.An object of a subclass can access the public methods of its superclass.
Solution
The correct statements are:
- An object of a superclass can access the public methods of the same superclass (itself).
- An object of a subclass can access the public methods of the same subclass (itself).
- An object of a subclass can access the public methods of its superclass.
The incorrect statement is:
- An object of a superclass cannot access the public methods of its subclass. This is because a superclass does not have knowledge about what a subclass has or does. It's the subclass that has knowledge about the superclass, not the other way around.
Similar Questions
Which of the following statements is correct?Public method is accessible only to subclasses of its parent classPublic method can only be called by object of its classPublic method is accessible to all other classes in the hierarchyPublic method can be accessed by calling object of the public class
Interpret which of the following statements are correct with respect to inheritance relationship in java? Select one or more:a.object of subclass referenced by super class type can access super class variablesb.object of subclass referenced by super class type can invoke newly defined sub class methodsc.object of subclass referenced by super class type can access newly defined sub class variablesd.object of subclass referenced by super class type can invoke super class methodse.object of subclass referenced by super class type can invoke overridden sub class methods
Which of the following statements are incorrect?Select one:when object of class is declared, each object contains its own copy of static variablesstatic methods must only access static datastatic methods can not refer to this or super in any waystatic methods can call other static methods only
Which of the following statements are incorrect?none of themprivate members of class can be accessed from subclasspublic members of class can be accessed by any code in the programprivate members of class can only be accessed by other members of the class
Which of the following is true?(A) All objects of a class share all data members of class(B) Objects of a class do not share non-static members. Every object has its own copy.(C) Objects of a class do not share codes of non-static methods, they have their own copy(D) None of the abovea.(C) Objects of a class do not share codes of non-static methods, they have their own copyb.(D) None of the abovec.(A) All objects of a class share all data members of classd.(B) Objects of a class do not share non-static members. Every object has its own copy.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.