Here we learn how to write a program in java to add two numbers. We made two class here but you have to save your file name with the second class name because compiler starts execution on that class where main () is placed.
class add_num
{
public int add (int a, int b)
{
return (a+b);
}
}
class Addnum
{
public static void main (String args[])
{
int a,b;
a=10;
b=23;
add_num addobj=new add_num();
System.out.println("Addition="+addobj.add(a,b));
}
}
Output::
class add_num
{
public int add (int a, int b)
{
return (a+b);
}
}
class Addnum
{
public static void main (String args[])
{
int a,b;
a=10;
b=23;
add_num addobj=new add_num();
System.out.println("Addition="+addobj.add(a,b));
}
}
Output::
techntips1.blogspot.com
ReplyDeletethanks fr sharing oracle training in chennai
ReplyDelete