Objects and Classes
Here we look into the concepts Classes and Objects.
- Object - Objects have behaviors and states. Instance: here is a dog which has states-color, name, breed as well as their behaviors - barking, wagging, eating. An object is an instance of a class.
- Class - Class could be defined as a template/ blue print which define the behaviors or states that object of its type support.
Objects in Java:
Let us now look deep into what are objects. If we consider the real-world we can search several objects around us, Dogs, Cars, Humans and many more. Where all these objects have a state and behavior
If we consider a dog then its state is. Name, color, breed and the behavior is. Wagging, Barking, running
If you compare the software object along with a real world object, they have very same features.
A Software objects also have a state and behavior. Software object's state is stored in fields and behavior is displays through methods.
Therefore in software development methods operate on the internal state of an object and the object-to-object communication is done by methods.
Classes in Java:
A class is a blue print from that individual objects are created.
A sample class is given below:
public class Dog{
String breed;
int age;
String color;
void barking(){
}
void hungry(){
}
void sleeping(){
}
}