How to create an object from class in Java?

Java 8Object Oriented ProgrammingProgramming

An object is created from a class using the new keyword. There are three steps when creating an object from a class −

  • Declaration − A variable declaration with a variable name with an object type.
  • Instantiation − The 'new' keyword is used to create the object.
  • Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object.

Example

public class Sample {
   public static void main(String args[]){
      Sample s = new Sample();
   }
}


raja
Published on 08-Jan-2018 11:21:04
Advertisements