Computer Applications
The correct statement to create an object named mango of class fruit:
- Fruit Mango= new fruit();
- fruit mango = new fruit();
- Mango fruit=new Mango();
- 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
If the name of the class is "Yellow", what can be the possible name for its constructors?
- yellow
- YELLOW
- Yell
- Yellow
Invoking a method by passing the objects of a class is termed as:
- Call by reference
- Call by value
- Call by method
- Call by constructor
Assertion (A): Static method can access static and instance variables.
Reason (R): Static variable can be accessed only by static method.
- Assertion and Reason both are correct.
- Assertion is true and Reason is false.
- Assertion is false and Reason is true.
- Assertion and Reason both are false.
What is the output of the Java code given below?
String color[] = {"Blue", "Red", "Violet"}; System.out.println(color[2].length());
- 6
- 5
- 3
- 2