2(x)
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.
Show SolutionHide Solution↓
(a)
Xavier 95
- A
performobjectob1is created usingnew perform(95, "Xavier"). - The constructor assigns
m = 95andname = "Xavier". - The
print()method outputs thenamefollowed by spaces and thenm.
(b) The constructor perform(int x, String y) accepts arguments, hence it is a parameterized constructor.