31. |
What will be the output of the following Java program?
class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj1 = new box(); box obj2 = new box(); obj1.height = 1; obj1.length = 2; obj1.width = 1; obj2 = obj1; System.out.println(obj2.height); } }
|
||||||||
Answer:
Option (a) |
32. |
What will be the output of the following Java program?
class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj = new box(); System.out.println(obj); } }
|
||||||||
Answer:
Option (d) |
33. |
What will be the output of the following Java code?
class area { int width; int length; int area; void area(int width, int length) { this.width = width; this.length = length; } } class Output { public static void main(String args[]) { area obj = new area(); obj.area(5 , 6); System.out.println(obj.length + "" "" + obj.width); } }
|
||||||||
Answer:
Option (c) |
34. |
What will be the output of the following Java program?
class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } class static_specifier { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + "" "" + obj2.y); } }
|
||||||||
Answer:
Option (d) |
35. |
What will be the output of the following Java program?
class access { static int x; void increment() { x++; } } class static_use { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.increment(); obj2.increment(); System.out.println(obj1.x + "" "" + obj2.x); } }
|
||||||||
Answer:
Option (c) |
36. |
What will be the output of the following Java program?
class static_out { static int x; static int y; void add(int a , int b) { x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + "" "" + obj2.y); } }
|
||||||||
Answer:
Option (c) |