Classes and Object Example in Java


Here is the simple program for printing example using classes and object in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class oops
{
  public static void main(String args[])
  {
   fun o =new fun();
   o.add();	
  }
}
class fun
{
  private int a,b;
  public void add()
  {
   Scanner in =new Scanner(System.in);
   System.out.print("\nEnter The Value Of A and B : \n");
   a=in.nextInt();
   b=in.nextInt();
   System.out.print("\nTotal : "+(a+b));
  }
}
To download raw file Click Here

Output

Enter The Value Of A and B :
12
23
Total : 35


Learn All in Tamil © Designed & Developed By Tutor Joes