KnowledgeBoat Logo

Computer Applications

The correct statement to create an object named mango of class fruit:

  1. Fruit Mango= new fruit();
  2. fruit mango = new fruit();
  3. Mango fruit=new Mango();
  4. fruit mango= new mango();

Java Classes

ICSE 2024

4 Likes

Answer

fruit mango = new fruit();

Reason — In Java, creating an object follows the syntax:

ClassName objectName = new ClassName();

Where:

  • ClassName: The name of the class.
  • objectName: The name of the object.
  • new: Allocates memory for the object.
  • ClassName(): Calls the class's constructor.

Thus, fruit mango = new fruit(); correctly creates mango named object of fruit class.

Answered By

2 Likes


Related Questions