Java new keyword example
- Details
- Written by Nam Ha Minh
- Last Updated on 19 August 2019   |   Print Email
In Java, the new keyword is used to create a new instance (object) of a class. For example, the following code creates a new object of class String:
String text = new String("Hello");
Create a new array object:
int[] numbers = new int[3];
Create a new instance of a class:
class Car { } Car newCar = new Car();
Related keywor: class. See all keywords in Java.
Other Recommended Tutorials:
- 9 Rules about Constructors in Java
- 12 Rules and Examples About Inheritance in Java
- 12 Rules of Overriding in Java You Should Know
- 10 Java Core Best Practices Every Java Programmer Should Know
- Understand Interfaces in Java
- Understand how variables are passed in Java
- Understand encapsulation in Java
Comments