Question:

Consider the following statements: \[ \texttt{Computer desktop = new Computer();} \] \[ \texttt{Computer Mainframe = new Computer();} \] Name the objects of the class given above:

Show Hint

In Java, the word before the object name is the class name, and the word between the class name and the equals sign is the object name. Also remember that Java is case-sensitive.
  • Desktop, Mainframe
  • desktop, Mainframe
  • Computer, Mainframe
  • Computer, desktop
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Understand the structure of object creation in Java.
In Java, an object is created using the syntax: \[ \texttt{ClassName objectName = new ClassName();} \] Here, the class name tells us which class is being used, and the variable name before the equals sign is the name of the object reference.
Step 2: Identify the class name and object names.
In the given statements: \[ \texttt{Computer desktop = new Computer();} \] \[ \texttt{Computer Mainframe = new Computer();} \] the class name is \texttt{Computer}. The object names are: \[ \texttt{desktop} \text{ and } \texttt{Mainframe} \] So, these are the two objects created for the class \texttt{Computer}.
Step 3: Check the options carefully.
  • (A) Desktop, Mainframe: Incorrect. The first object is \texttt{desktop}, not \texttt{Desktop}. Java is case-sensitive.
  • (B) desktop, Mainframe: Correct. These exactly match the object names in the statements.
  • (C) Computer, Mainframe: Incorrect. \texttt{Computer} is the class name, not an object name.
  • (D) Computer, desktop: Incorrect. \texttt{Computer} is again the class name, not an object.
Step 4: Conclusion.
Therefore, the objects of the class given above are desktop and Mainframe.
Final Answer:desktop, Mainframe.
Was this answer helpful?
0
0

Top Questions on Object-Oriented Programming

View More Questions