Tuesday, 27 August 2013

Class in JAVA


BASIC
All the objects that have similar properties and similar behavior are grouped together to form a class. Class is the java way to implement encapsulation.A class is a user defined data type and objects are the instance variables of class.



GENERAL FORM OF CLASS

A class is declared by use of the class keyword.The data, or variables, defined within a class are called instance variables because each instance
of the class (that is, each object of the class) contains its own copy of these variables.
class class name {
type instance variable;
//
type method name(parameter-list) {
//body of method
}
to access the instance variables and methods declared within a class and assign values to instance variable we need to create object of class using dot (.) operator.
object of class is created as classname obj =new classname();
class area(){
double length;
double width;
}
class calculatearea()
{
public static void main(String args[])
{
area obj=new area();
double area;
obj.length=9;
obj.breath=4;
area=obj.length*obj.breath;
System.out.printllln(“area is”+area);
}
}


concept of object
object of a class is created by new operator.

The new operator dynamically allocates (that is, allocates at run time) memory for an object and returns a reference to it. This
reference is, more or less, the address in memory of the object allocated by new.This reference is then stored in the variable.


Related Posts:

  • JAVA : Collections                     Collections And Framework                           … Read More
  • Access modifers in java  Java's access specifiers are  : - 1. Public, 2. Private, 3.Default, and 4.Protected.  Java also defines a default access level. protected applies only when inheritance is involved. The other access specifiers… Read More
  • History of JAVA Java is a general-purpose, concurrent, class-based, object-oriented computer programming language that is specifically designed to have as few implementation dependencies as  &nbs… Read More
  • Top wesbites to learn Java Wish to create your software games and web applications .Here i suggest some resource for you. Now you habe to practice the things which you read theoretically. It will help to sharp your skills .Apart from us LANG-ADDA the… Read More
  • Installing JAVA AND Setting CLASS PATH  Installing JAVA AND Setting CLASS PATH        Install jdk 7.4(latest version) or any  other lower                    version.   &… Read More

0 comments:

Post a Comment