Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Monday, 27 July 2015

Object and Class in java

The Concept of Object and Class in Java

Object in Java


Basically an entity that has state and behavior is known as an object. It has three main characteristics like state,behavior and identity.

Object is an instance of a class.

Object and Class

Class in java



A class is a group of objects that has common properties.

A class can be defined as a template/ blue print that describes the behaviors/states that object of its type support.

Syntax to declare a class

class {  

    data member;  

    method;  

}  



Sample Program:


class FirstProgram{

   int a;     //data member
   String name;//data member
   public static void main(String args[]){  
      
      FirstProgram fp=new FirstProgram();  //creating an object of FirstProgram
      System.out.println(fp.a);  
      System.out.println(fp.name);
   }
}  


Output:


0
null


Note: The Output of the program shows the default values in the variables 'a' and 'name'.

Sunday, 19 January 2014

FUNDAMENTAL CLASS PATTERNS IN JAVA

A class the basic building block of an object-oriented language such as Java is a template that describes the data and behavior associated with instances of that class. The data associated with a class or object is stored in variables; the behavior associated with a class or object is implemented with methods.