Full width home advertisement

Post Page Advertisement [Top]

JAVA Classes, Java Objects and its Instance

Java Classes
In Java, codes are written under a body called class.

Example: a class with name "MyClass

class MyClass

{


}


Objects and Instance

Objects are the real world character created in Java.
It may be car, animal, home, etc...

This class can be taken as object in other class as well as in their own class.

When we take class as a object then its called a instance of a class.

Object can be created by using this syntax: ClassName variableName = new ClassName();

Example:


class Car
{

   public static void main(String args[])

  {

     Car safari=new Car();

  }

}

Where, 

Car is the name of class.

safari is a variable, used to create a  instance of the class Car.

new is keyword of Java used to make a new copy of any object.


  Prev: A Hello World Example    - Next: Creating Objects

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib