Class and Objects
Class : A class can be defined as a blueprint or a set of instruction to build a specific type of object. Class show how to declare fields, methods, and constructors.
we declare a class by specifying the class keyword followed by a non-reserved identifier that names it. A pair of matching open and close brace characters ({ and }) following it.
class className
{
//body
}
E.g. : class Student
{
Int rollno;
String name;
void setRollno( );
}
Objects : Objects have states and behaviors. Example: A dog has states – color, name, breed as well as behaviors – wagging the tail, barking, eating. An object is an instance of a class.
Other definitions of object include :
- Object is a real world entity.
- Object is a run time entity.
- Object is an entity which has state and behavior.
- Object is an instance of a class.