Professional Documents
Culture Documents
Submitted by:
Jay Menard Roble
Jian librez
What is creating classes object?
When you create an object, you are creating
an instance of a class, therefore "instantiating" a
class. The new operator requires a single,
postfix argument: a call to a constructor. The
name of the constructor provides the name of
the class to instantiate. The constructor
initializes the new object.
How to Create an Object?
In Java, an object is created from a class.
We have already created the class
named Main, so now we can use this to
create objects. To create an object
of Main, specify the class name, followed
by the object name, and use the
keyword new.
Example:
Create an object called "myObj" and print
the value of x:
public class Main { int x = 5; public static
void main(String[] args) { Main myObj =
new Main(); System.out.println(myObj.x);
What are classes and objects?