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
}
}
1 Rahim
2 Ram
Press any key to continue . . .
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.