Object and class in Java

Object Oriented ProgrammingJava8Java Programming

When we consider a Java program, it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what do class, object means.

  • Object − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class.
  •  Class − A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports.

Example

Live Demo

public class Tester {
   public void message(){
      System.out.println("Hello World!");
   }
   public static void main(String args[]) {
      Tester tester = new Tester();
      tester.message();
   }
}

Here Tester is class and tester is its object.

raja
Published on 23-Apr-2018 06:55:52
Advertisements