Classes And Object in java with Example

Classes And Object in java with Example

Classes are the template or a blue print for the object. Class is act as a container for object.
Object concept are derived from the real world object. It seems as a real world object like a car , a apple etc.

Example

Like an orange, an apple, grapes all are fruit so they can be contained into class name fruit. The structure is given below

class fruit {
  String apple;
  String orange;
  String grapes;
}

The concept of class and object are the basic concept of object oriented programming language which change the way of programming.

It make a programming more simplified and understandable because a programmer can start programming by take a example of real world.

A full example of class and object with output is given below:

public class ClassExample {
  String str = " Class and object example ";
  public static void main(String args[]) {
    ClassExample obj = new ClassExample();
    System.out.print(obj.str);
  }
}

Output

Class and object example

Above program explanations

ClassExample is name of class
String str; -> str is a variable String is a datatype
ClassExample tc=new ClassExample();
obj is an object that access the apple value;