Saturday 18 August 2012

CLASS IN JAVA !!


Hello Friends !! Today we are starting the concept of class.



Introduction to class !!


  • A class is basically consist of data member and member function.
  • Typically ,a class is declared by using the keyword class .

Syntax of basic class structure:
class  classname
{
Type instance-variable1;
Type methodname(parameter-list)
{
//body of method
}
}
Data ,or variables ,defined within in a class are called instance  variables.

The code is contained within the methods.
 A simple class :
class abc{
int x;
int  y;
}
Create an object of class abc:
abc a1=new abc();
where abc is class name and abc() is constructer
to assign value to the int x with the help of object :
a1.x=10;
a1.y=2;
/* here is the complete program that uses the abc class…
/* save this file as def.java
*/
class abc{
int x;
int y;
}
//this class declare an object of type abc
class def
{
public static void main(String[] args)
{
abc a1=new abc();
int z;
a1.x=10;
a1.y=2;
z=a1.x * a1.y;
System.out.println(“the product of x & y” + z );
}
}
o/p:
the product of x &y 20

Now !! You can download the copy of this article in pdf format by just click on below download link....

If still You have any query regarding  to this  article then please post your comment i will 100% reply back  you…..Thanks……:)

0 comments:

Post a Comment

Hey thanax alot to comment i will revert you back soon...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites