Which of the following can be used to create an object in Java?

Java MCQ: Which of the following can be used to create an object in Java?

a) new
b) malloc
c) alloc
d) calloc

Answer:

a) new

Explanation:

In Java, the new keyword is used to create an object of a class. It dynamically allocates memory for the object and returns a reference to it. For example, MyClass obj = new MyClass(); creates an object of MyClass.

Other options like malloc, alloc, and calloc are not used in Java. They are functions from the C programming language used for memory allocation, but Java has built-in memory management through the new keyword and garbage collection.

Understanding object creation and memory management is key to writing effective Java programs that utilize resources efficiently.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top