Parameterized Constructor, constructor present in another class

Java Programming Language / Class, Object and Methods in java

1067

Program:

 // Here is a simple example that uses a constructor with parameters
class ConstructorClass {
   int x;

      // Following is the constructor
      ConstructorClass(int i ) {
         x = i;
   }
}

// You will have to call constructor to initialize objects as follows
public class MainClass {

   public static void main(String args[]) {
         ConstructorClass t1 = new ConstructorClass( 10 );
         ConstructorClass t2 = new ConstructorClass( 25 );
         System.out.println(t1.x + " " + t2.x);
   }
}

Output:

10 25
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.