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 obj1 = new box(); box obj2 = new box(); obj1.height = 1; obj1.length = 2; obj1.width = 1; obj2 = obj1; System.out.println(obj2.height); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: When we assign an object to another object of same type, all the elements of right side object gets copied to object on left side of equal to, =, operator. |
2. |
In the below code, which call to sum() method is appropriate? class Output { public static int sum(int ...x) { return; } static void main(String args[]) { sum(10); sum(10,20); sum(10,20,30); sum(10,20,30,40); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: sum is a variable argument method and hence it can take any number as argument. |
3. |
Which of the following statements are incorrect? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: finalize() method is called just prior to garbage collection. it is not called when object goes out of scope. |
4. |
What is the output of this program? class test { int a; int b; void meth(int i , int j) { i *= 2; j /= 2; } } class Output { public static void main(String args[]) { test obj = new test(); int a = 10; int b = 20; obj.meth(a , b); System.out.println(a + " " + b); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: Variables a & b are passed by value, copy of their values are made on formal parameters of function meth() that is i & j. Therefore changes done on i & j are not reflected back on original arguments. a & b remain 10 & 20 respectively. |
5. |
Which of these access specifier must be used for class so that it can be inherited by another sub class? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: None. |
6. |
What is the output of this program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: arr.length() is 5, so the loop is executed for three times. |
7. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "hello"; String obj1 = "world"; String obj2 = obj; obj2 = " world"; System.out.println(obj + " " + obj2); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
8. |
What is the output of this program? class A { public int i; public int j; A() { i = 1; j = 2; } } class B extends A { int a; B() { super(); } } class super_use { public static void main(String args[]) { B obj = new B(); System.out.println(obj.i + " " + obj.j) } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: Keyword super is used to call constructor of class A by constructor of class B. Constructor of a initializes i & j to 1 & 2 respectively. |
9. |
What is the output of this program? class Abc { public static void main(String[]args) { String[] elements = { "for", "tea", "too" }; String first = (elements.length > 0) ? elements[0]: null; } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: The value at the 0th position will be assigned to the variable first. |
10. |
What is the output of this program? class Output { public static void main(String args[]) { Object obj = new Object(); System.out.print(obj.getclass()); } } |
|||||||||||||||||||
|