String ta = "A "; ta = ta.concat("B "); String tb = "C "; ta= ta.concat(tb); ta.replace('C', 'D'); ta=ta.concat(tb); System.out.println(ta);
}
What is the result?
1. A B C D 2. A C D 3. A B C C 4. A B D 5. A B D C
Correct Answer : 3
Explanation: String is a immutable class. Hence, replace method will give new instance of the class. However, we are not using the return value of the replace method. So the actual string will not be altered. Hence, C will not be replaced by D. So final string will be ABCC
Question : Given: Which option enables the code to compile? 1. Replace the code fragment at line n1 with : class Book implements Readable { 2. At line n2 insert : public abstract void setBookMark(); 3. Replace the code fragment at line n3 with : abstract class EBook extends Book { 4. At line n4 insert: public void setBookMark() {}
Correct Answer : 3
Explanation: If you are not implementing all the methods of a super class than you have to mark subclass as a abstract class.
Question : Given the code fragment: What is the result? 1. Match 1 2. Match 2 3. No Match 4. A NullPointerException is thrown at runtime.
1. Adding the public modifier to the declaration of method1 at line n1 2. Removing the public modifier from the definition of method1 at line n2 3. Access Mostly Uused Products by 50000+ Subscribers 4. Changing the line n4 DoClass doi = new DoClass ( );