You are on page 1of 8

Creating classes Object

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?

The basic difference between Class and Object is


that Class is a user-defined datatype that has its
own data members and member functions whereas
an object is an instance of class by which we can
access the data members and member functions of
the class.
Why do we create class Objects?

 Objects are required in OOPs(Object-oriented


programming is a method used for designing a program
using classes and objects. Object-oriented programming is
also called the core of java.) because they can be created to
call a non-static function which are not present inside the
Main Method but present inside the Class and also provide
the name to the space which is being used to store the data.
Thank u

You might also like