Premium

Oracle Java Programming Certification Questions and Answers (Dumps and Practice Questions)



Question : Given:

public static void main(String args[]){

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?

 :   Given:
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?
 :  Given:
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?
 :  Given the code fragment:
1. Match 1
2. Match 2
3. No Match
4. A NullPointerException is thrown at runtime.




Correct Answer : 2


Related Questions


Question : You have been given following code

int a = 0;
a++;
System.out.println(a++);
System.out.println(a);

What would be the result ?

 : You have been given following code
1. 1

2. 0

3. Access Mostly Uused Products by 50000+ Subscribers

4. 2





Question : You have been given following code

public class Test {
public static void main(String[] args) {
int arr[] = new int[4];
arr[0] = 1;
arr[1] = 2;
arr[2] = 4;
arr[3] = 5;
int sum = 0;
try {
for (int pos = 0; pos <= 4; pos++) {
sum = sum + arr[pos];
}
} catch (Exception e) {
System.out.println("Invalid index");
}
System.out.println(sum);
}
}

What would be printed ?
 : You have been given following code
1. 12
2. Invalid Index 12
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails





Question : :
int [] array = {1,2,3,4,5};
for (int i: array) {
if ( i < 2) {
keyword1 ;
}
System.out.println(i); if ( i == 3) {
keyword2 ;
}}

What should keyword1 and keyword2 be respectively, in oreder to produce output 2345?
 : :
1. continue, break
2. break, break
3. Access Mostly Uused Products by 50000+ Subscribers
4. continue, continue





Question :

package p1;
public interface DoInterface {
void method1(int n1); // line n1
}

package p3;
import p1.DoInterface;
public class DoClass implements DoInterface {
public DoClass(int p1) { }
public void method1(int p1) { } // line n2
private void method2(int p1) { } // line n3
}

public class Test {
public static void main(String[] args) {
DoInterface doi= new DoClass(100); // line n4
doi.method1(100);
doi.method2(100);
}
}
Which change will enable the code to compile?

 :
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 ( );




Question : Consider

Integer number = Integer.valueoff 808.1");

Which is true about the above statement?

 : Consider
1. The value of the variable number will be 808.1
2. The value of the variable number will be 808
3. Access Mostly Uused Products by 50000+ Subscribers
4. A NumberFormatException will be throw.
5. It will not compile




Question : You have been given following code

public class MyFor {
public static void main(String[] args) {
for (int ii = 0; ii < 4; ii++) {
System.out.println("ii = " + ii);
ii = ii + 1;
}
}
}

What is the result?

 : You have been given following code
1. ii = 0 ii = 2
2. ii = 0 ii = 1ii = 2 ii = 3
3. Access Mostly Uused Products by 50000+ Subscribers

4. Compilation fails.