Ask Question
29 October, 19:07

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. 29 October, 19:34
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers