Parameterized Constructor, constructor present in same class, with method
Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)
966Program:
class ParameterizedConstructor{ int rollno; String name; // it is constructor ParameterizedConstructor(int i,String n){ rollno = i; name = n; } // it is method void display(){ System.out.println(rollno+" "+name); } public static void main(String args[]){ ParameterizedConstructor s1 = new ParameterizedConstructor(1,"Rahim"); ParameterizedConstructor s2 = new ParameterizedConstructor(2,"Ram"); s1.display(); // invoke method using object s1 s2.display(); // invoke method using object s2 } }
Output:
1 Rahim 2 Ram 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.