1. C B A 2. C 3. A B C 4. Compilation fails at line n1 and line n2
Correct Answer : 3 Explanation: When you have hierarchy in java code, and calling a constructor will first call default constructor of super class. In given code, we are creating instance of class C , which will call constructor of class C , before calling class C constructor it will call Class B constructor and Class B constructor will call default constructor of class A (Hierarchy end here). Hence, first A, then B and then C will be printed here.
Question : Given the code fragment:
What is the result?
1. [Robb, Rick, Bran] 2. [Robb, Rick] 3. [Robb, Bran, Rick, Bran] 4. An exception is thrown at runtime.
Correct Answer : 1 Explanation: public boolean remove(object o) Removes the first occurrence of the specified element from this list, if it is present (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that (o==null ? get(i) == null : o.equals(get(i))) (if such an element exists). Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call). Parameters: o - element to be removed from this list, if present Returns: true if this list contained the specified element
Question :
1. Replace line n2 with e.name="Joe"; e.contract=true; e.salary=100;
2. Replace line n2 with this.name="Joe"; this.contract=true; this.salary=100;
3. Replace line n1 with this.name=new String("Joe"); this.contract=new Boolean(true); this.salary=new Double(100);
4. Replace line n1 with name="Joe"; contract=TRUE; salary=.0f;
1. Sum is 600 2. Compilation fails at line n1. 3. Compilation fails at line n2. 4. A ClassCastException is thrown at line n1. 5. A ClassCastException is thrown at line n2.