Tuesday, 27 November 2018

Java - Class


  It is a user defined data type and behaves like the built in types.

  Class is a template to create an object.

 The entire set of data and code of an object can be made a user defined data type, with the help of class.

  By creating class, really we are establishing the way to create the objects.

  Class can have constructors, methods, instance variables.

  In java, classes can be available in two types
o   Concrete class – Instantiation is possible
o   Abstract class - Instantiation is not possible
Instantiation means object creation.
Structure of class
[modifier] class A
{
//instance variables declaration
//static variables declaration
//constructors
//instance methods
//static methods
}
Example
class A
{
int x,y;
static int p,q;
    A()
          {
               //code
          }
    void get(int x,int y) // instance method
          {
               //code
          }
    static void getter(int p,int q) //static method
          {
               //code
          }
}


No comments:

Post a Comment

Note: only a member of this blog may post a comment.