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 main_class { public static void main(String args[]) { int x = 9; if (x == 9) { int x = 8; System.out.println(x); } } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Two variables with the same name can’t be created in a class. |
2. |
What is the output of this program? class box { int width; int height; int length; int volume; void volume(int height, int length, int width) { volume = width*height*length; } } class Prameterized_method{ public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(3,2,1); 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; box() { width = 5; height = 5; length = 6; } void volume() { volume = width*height*length; } } class constructor_output { public static void main(String args[]) { box obj = new box(); obj.volume(); System.out.println(obj.volume); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: None. |
4. |
What is the output of this program? class overload { int x; int y; void add(int a) { x = a + 1; } void add(int a, int b){ x = a + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 0; obj.add(6); System.out.println(obj.x); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
5. |
What is the output of this program? class access{ public int x; private int y; void cal(int a, int b){ x = a + 1; y = b; } } class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x + " " + obj.y); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
6. |
Which of these methods must be made static? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: main() method must be declared static, main() method is called by Java’s run time system before any object of any class exists. |
7. |
What is the output of this program? class string_demo { public static void main(String args[]) { String obj = "I" + "like" + "Java"; System.out.println(obj); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Java defines an operator +, it is used to concatenate strings. |
8. |
What is the output of this program? class A { int i; void display() { System.out.println(i); } } class B extends A { int j; void display() { System.out.println(j); } } class inheritance_demo { 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 C Explanation: class A & class B both contain display() method, class B inherits class A, when display() method is called by object of class B, display() method of class B is executed rather than that of Class A. |
9. |
Which of these is supported by method overriding in Java? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
10. |
Which of these class relies upon its subclasses for complete implementation of its methods? |
|||||||||||||||||||
|