Java OCA OCP Practice Question 794


Given the following code, which statements are true?

class MyBaseClass { 
   int i; 
class MyClass extends MyBaseClass { 
   int j; 

Select 3 options

  • A. Class MyClass extends class MyBaseClass.
  • B. Class MyClass is the superclass of class MyBaseClass.
  • C. Class MyBaseClass inherits from class MyClass.
  • D. Class MyClass is a subclass of class MyBaseClass.
  • E. Objects of class MyClass will always have a member variable named i .

Correct Options are  : A D E


Here are a few good words from the Java Language Specification:

Members of a class that are declared private are not inherited by subclasses of that class.

Only members of a class that are declared protected or public are inherited by subclasses declared in a package other than the one in which the class is declared.

Constructors and static initializers are not members and therefore are not inherited.