Ask Question
10 June, 20:15

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. 10 June, 22:47
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers