4 October 2013

JAVA Practical File (Btech)

AIM:- Write a program in JAVA to demonstrate constructor use.

Program:-


class Test
{
int x,y;
Test()
{
x=y=0;
}
Test(int m )
{
x=y=m;
}
Test(int x, int y)
{
this.x=x;
this.y=y;
}
void sum()
{
int c=x+y;
System.out.println("Sum of two numbers is"+" "+c);
}
}
class Test3
{
public static void main (String args [])
{
Test t1=new Test();
Test t2=new Test(40);
Test t3=new Test(30,30);
t1.sum();
t2.sum();
t3.sum();
}
}


Output:-  Sum of two numbers is 0
               Sum of two numbers is 80

               Sum of two numbers is 60


2 comments:

Your Blog post has exceptionally supportive data.

Much obliged concerning share.... .

Continue offering
Correspondence Courses

http://technobracket.blogspot.in/2012/11/best-sites-for-btech-projects-for-all.html?showComment=1430375673554#c8181043515696818972

Post a Comment