Core Java

Class

-> A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviors.

-> for example, consider a class vehicle which has properties such as color, size, manufacturing company etc.

-> A class can contain fields and methods to describe the behavior of an object.

-> Methods are nothing but members of a class that provide a service for an object or perform some business logic.

Object

-> An Object is an variable of class type.

-> An Object is an real world entity that has state and behaviour eg : car, bus, chair etc.

-> An Object is created using new keyword.

-> Objects are stored in heap memory and its reference is stored in stack.


example:

public class Vehicle
{

// method

void getVehicle()
{
System.out.println("This is a vehicle class");
}

//main method

public static void main(String args[])
{
Vehicle vehicle=new Vehicle(); // object creation
vehicle.getVehicle();
}
}


output: This is a vehicle class


No comments:

Post a Comment