Instruction
- Total number of questions : 10.
- Time alloted : 10 minutes.
- Each question carry 1 mark.
- No Negative marks
- DO NOT refresh the page.
- All the best :-).
1. |
What is the output of this program? class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj = new box(); obj.width = 10; obj.height = 2; obj.length = 10; int y = obj.width * obj.height * obj.length; System.out.print(y); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: None. |
2. |
What is the output of this program? class box { int width; int height; int length; int volume; void volume() { volume = width*height*length; } } class Output { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(); System.out.println(obj.volume); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
3. |
What is the output of this program? class box { int width; int height; int length; int volume; void finalize() { volume = width*height*length; System.out.println(volume); } protected void volume() { volume = width*height*length; System.out.println(volume); } } class Output { public static void main(String args[]) { box obj = new box(); obj.width=5; obj.height=5; obj.length=6; obj.volume(); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: None. |
4. |
What is the output of this program? class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d){ y = c + d; } overload() { this.x = 0; this.y = 0; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 2; double b = 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + " " + obj.y); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: For obj.add(a,a); ,the function in line number 4 gets executed and value of x is 4. For the next function call, the function in line number 7 gets executed and value of y is 6.4 |
5. |
What is the output of this 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); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
6. |
What is the output of this 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); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
7. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.length()); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
8. |
What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: class contains a private member variable j, this cannot be inherited by subclass B and does not have access to it. |
9. |
What is the output of this program? final class A { int i; } class B extends A { int j; System.out.println(j + " " + i); } class inheritance { public static void main(String args[]) { B obj = new B(); obj.display(); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: class A has been declared final hence it cannot be inherited by any other class. Hence class B does not have member i, giving compilation error. |
10. |
What is the output of this program? class A { int i; int j; A() { i = 1; j = 2; } } class Output { public static void main(String args[]) { A obj1 = new A(); A obj2 = new A(); System.out.print(obj1.equals(obj2)); } } |
|||||||||||||||||||
|