Class and Object in java

What is class?

A class in Java is a Blueprint or template from which an object is created. The object is defined by the Structure and behaviour(methods) that objects of that class will possess.
It is a logical entity.
No memory is allocated when a c…


This content originally appeared on DEV Community and was authored by vishnu vishnu

What is class?

  • A class in Java is a Blueprint or template from which an object is created. The object is defined by the Structure and behaviour(methods) that objects of that class will possess.

  • It is a logical entity.

  • No memory is allocated when a class is defined.

  • All classes are non-primitive datatypes.

How to create a class?

**
BASIC SYNTAX for creating a class:**

public class Car
{
    // Data members (fields)- hold  the actual value

String brand;
int speed;
    //Behaviour (method)
void drive()

{
System.out.println("driving a car");
}


}
//But it’s not a real car yet. It’s just the plan.

Class Name Rules:

  1. Must start with an Uppercase first letter or (_) underscore or dollar sign ($).
  2. can not start with a number
  3. cannot contain spaces or special characters
  4. Use Pascal-case for naming

What is an Object?

  • An object is an instance of a class, and it has its own memory copy. It is a physical entity. An object is created with the new keyword.

  • When a class is created, no memory is used. Memory is allocated only when an object is created from that class.

Creating an Object :
classname, reference var,assignment operator,new keyword,classname();

Student id = new Student();


This content originally appeared on DEV Community and was authored by vishnu vishnu


Print Share Comment Cite Upload Translate Updates
APA

vishnu vishnu | Sciencx (2025-11-26T01:23:12+00:00) Class and Object in java. Retrieved from https://www.scien.cx/2025/11/26/class-and-object-in-java-2/

MLA
" » Class and Object in java." vishnu vishnu | Sciencx - Wednesday November 26, 2025, https://www.scien.cx/2025/11/26/class-and-object-in-java-2/
HARVARD
vishnu vishnu | Sciencx Wednesday November 26, 2025 » Class and Object in java., viewed ,<https://www.scien.cx/2025/11/26/class-and-object-in-java-2/>
VANCOUVER
vishnu vishnu | Sciencx - » Class and Object in java. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/26/class-and-object-in-java-2/
CHICAGO
" » Class and Object in java." vishnu vishnu | Sciencx - Accessed . https://www.scien.cx/2025/11/26/class-and-object-in-java-2/
IEEE
" » Class and Object in java." vishnu vishnu | Sciencx [Online]. Available: https://www.scien.cx/2025/11/26/class-and-object-in-java-2/. [Accessed: ]
rf:citation
» Class and Object in java | vishnu vishnu | Sciencx | https://www.scien.cx/2025/11/26/class-and-object-in-java-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.