what is class and object in java?

  

Java is a object oriented programming language.

CLASS IN JAVA:

    A class like a object constructor or a blueprint for creating the object. The class name first letter must be at Upper case. The class name and the file name must be same.
   A small example for class in java.

Example.java

public class Example{

    System.out.println("hello world");

}

In this program we have named the class as Example. The file name also be the same as Example.java.

OBJECTS IN JAVA:

  Object was created inside the class. In object declaration we  have to use the keyword new. A small example for Objects in java.

Example.java

public class Example{

int x=9;

public static void main(String[] args){

Example myobj=new Example();

System.out.println(myobj.x);

   }
}

  In this program we have named the file name as Example.java. we have named the class as same that is Example. we have declared the x in the integer with the value of 9. 

1 Comments

Post a Comment

Post a Comment

Previous Post Next Post