KnowledgeBoat Logo
|

Computer Applications

class perform 
{ 
int  m;  String name; 
perform(int x, String y) 
{ 
m=x; 
name=y; 
} 
void print()  
{ 
System.out.print(name + "     " + m); 
}      
public static void main() 
{ 
perform ob1=new perform(95 , "Xavier"); 
ob1.print();
} 
}

(a) Give the output of the code given above.

(b) Name the type of the constructor used.

Java Constructors

4 Likes

Answer

(a)

Output
Xavier     95
Explanation
  • A perform object ob1 is created using new perform(95, "Xavier").
  • The constructor assigns m = 95 and name = "Xavier".
  • The print() method outputs the name followed by spaces and then m.

(b) The constructor perform(int x, String y) accepts arguments, hence it is a parameterized constructor.

Answered By

3 Likes


Related Questions