Class and Objects in Java

What is Class?

class is nothing but a template for object you are going to create or it’s a blueprint by using this we create an object.

  • Class contains Variables and Methods.

Syntax:

Access Modifier  –  Defines who can access this class and it’s members.

Name  –  Unique name for the class.

Super Class name  –  Super class of given class.

Interface Name  –  Name of Interface Class.

Example Of Class:

 

 Output:

 

What is Object?

Objects are anything that exists in the world. A Class is a blueprint to develop objects.

Syntax:

Here constructor of the class(Class_Name) will get executed and Object will get created(Object Reference will hold the reference of created object in memory).

How to Access Member of a Class :

You can call a method of an object by naming the object followed by a period (dot), followed by the name of the method and its argument list, like this.

Syntax:

 Example:

 

 Output:

 

Manikandan is Founder and author of codenread. Tech Blogger by Passion | Computer Science Engineer by Qualification