answersLogoWhite

0

What does the java new operator do?

Updated: 10/18/2022
User Avatar

Wiki User

15y ago

Best Answer

The new keyword tells Java that you want to create a new instance of a class by invoking one of the constructors for that class.

// Create a new, empty String object

String s1 = new String();

// Create a new String object with a different constructor

String s2 = new String("howdy");

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

The new operator is used to create a new instance of an object.

Example:

ArrayList lst = new ArrayList();

This statement is used to create a new object of type ArrayList

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does the java new operator do?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Explain how objects are created in Java?

with new operator


Explain the role of sizeof operator in java?

There is no sizeOf() operator in Java.


Which operator works like sizeof operator in Java?

Java does not have the sizeOf() operator or any operator that gives an equivalent result.


Why are you used new operator in main method in java?

new is used for memory allocation in java which on later automatically deallocated by garbage collector.


Operator overloading is possible in java or not?

Java does not support opperator overloading, so the answer to your question is: none.


What are the restriction that are applied to operator overloading?

Java does not support user defined operator overloading.The operator '+' is overloaded in Java and can be used for adding both numbers and Strings.


When the Java Virtual Machine sees the new operator in a program it instantiates an object for a specified class.?

Yes.


What is operator in java?

An operator is a symbol that does something in Java. for ex: "+" is an arithmetic operator that adds two numbers. ">" is a logical operator that checks if one number is greater than the other. There are many different types of operators in Java like Arithmetic, Logical, Relational and Assignment operators


What happen when a java keyword new is used in an application?

When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.


Difference between equals equals and equal in java?

"==" in java is the binary operator which compares two values and gives a boolean result While "=" in java is a assignment operator which assigns a value to a variable.


The multiplication operator is represented in Java by what symbol?

In Java, the multiplication operator is represented by the asterisk, "*". This was not invented by Java; most programming languages, as well as programs such as Excel, use the same symbol.


What is use of new operator is it necessary to be used when object of the class is crated why?

In the case of the Java language, it is necessary. The reason is because that's how creating objects was defined in Java. Note that a method can return an object, so the use of the "new" operator may be hidden: x = SomeClass.someMethod(); In this example, is someMethod() returns an object, x will point to this object; however, the "new" operator is still used in the method someMethod().