What is the use of new keyword in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the use of new keyword in java?

14th Dec 2019, 4:09 PM
Pranita
Pranita - avatar
4 Answers
+ 2
Java is object oriented programming language. Suppose you would like to design a 'dog' object. You will have to create a Dog.java file which contains a 'public class Dog {}' This class is the object definition. And to 'create' one dog instance using the definition, you will use 'new' keyword with for example the 'new Dog()' instruction. Dog bobby = new Dog();
14th Dec 2019, 4:18 PM
Brice Vandeputte
Brice Vandeputte - avatar
+ 4
"new" keyword is used to create an object of a class. Only after you use a new keyword, a memory block on the heap is allocated for that object.
14th Dec 2019, 4:13 PM
Avinesh
Avinesh - avatar
+ 2
New key word will help to create object to class
15th Dec 2019, 3:43 AM
Samavedam Praneeth
Samavedam Praneeth - avatar
+ 1
I think that going through the Java tutorial may help.
15th Dec 2019, 3:23 AM
Sonic
Sonic - avatar