Definition of Class
A class in java is a blueprint or template used to create the object. It defines the data members(variable) and method(function) that describe the state and behaviour of the object.
What is class?
class is a blueprint or template.
class is a keyword in java.
It is a logical entity.(we won't store anything we jus create the class).
First letter of the class must be capital.
We can use special character $,_.
Numeric are not allowed in beginning.
Camelcase can be used.(i.e,ParentChild)
class is a collection of object.
It is a user defined data types.
class contains instance variable, methods, nested class & blocks, interface, constructor.
class supports the concept of encapsulation ,polymorphism and inheritance in oop's concept.
syntax of class:
class ClassName{
}
For example:
public class Car{
String name;
int model_year;
void model(){
System.out.println(name);
}
}
where Car is a class,name and model_year are attributes and model() is a method.
Definition of object
An object is a instance of a class that is created by the keyword "new". It has unique identity, state(attributes) and behaviour(methods).
what is oject?
Object is a instance of a class.
object is a combination of state and behaviour.
It is a physical entity.
syntax of object:
Classname referencename=new Classname();
"new" is a keyword.The keyword new will create a memory inside the heap memory.This done by JVM.
First letter of the referencename must be small.
$,_ can be used.
Numeric are not allowed in beginning.
For example:
Car mycar=new Car();
Car is a class.
my car is a object of the car class.
Top comments (0)