Ask Question
4 July, 10:19

Suppose that the class Mystery is derived from the class Secret. Consider the following statements.

Secret mySecret = new Secret ();

Secret secRef;

Mystery myMystery = new Mystery ();

Mystery mysRef;

secRef = myMystery;

Which of the following statements is legal in Java?

(i) mysRef = (Mystery) mySecret;

(ii) mysRef = (Mystery) secRef;

+4
Answers (1)
  1. 4 July, 10:35
    0
    The answer to the following question is the option " (ii) ".

    Explanation:

    In the java code firstly we create the derived class (Secret) object and reference variable that is mySecret and secRef. Then we create a base class (Mystery) object and reference variable that is myMystery and mysRef. In the derived class reference variable that holds the base class object. So the legal statement in java is "mysRef = (Mystery) secRef". In this code, the reference variable of the base class holds the value of the base class object and derived class reference variable.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Suppose that the class Mystery is derived from the class Secret. Consider the following statements. Secret mySecret = new Secret (); Secret ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers