0

This example explains how we can use two classes in java programming 

class Example
{
     int a, b, total;     // instance variables
     void add()           // method
     {
          total = a + b;
     }
}
class Geekyshows         // main class
{
     public static void main (String args[])      // main method
     {
          Example obj = new Example();          // object creating
          obj.a = 10;                           // variable initializing
          obj.b = 20;                          // variable initializing
          obj.add();
          System.out.println("Addition = "+obj.total);
     }
}


Post a Comment

Comment Rules :
1. Do not post Adult/illegal Links.
2. Try to comment in only English Language.
3. Do not post other website's links which are useless.
4. Your Comment should be based on the Topic for other queries Kindly Visit our Contact Us Page.
5. Do not use Abusive Language.
6. Respect each other.
Thank You for following the rules. Please Comment....

 
Top