Premium

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



Question : Given the code fragment:
String h1 = "Bob";
String h2 = new String ("Bob");
What is the best way to test that the values of h1 and h2 are the same?

  : Given the code fragment:
1. if (h1 = = h2)
2. if (h1.equals(h2))
3. Access Mostly Uused Products by 50000+ Subscribers
4. if (h1.same(h2))


Correct Answer : Get Lastest Questions and Answer :
Explanation: The equals method compares values for equality










Question : You have been given belwo interface declaration

interface Runnable {
public voide run();
}

Which of the following will create instance of Runnable type?

   : You have been given belwo interface declaration
1. Runnable run = 0 -> {
System.out.println("Run");
}
2. Runnable run = 0 -> System.out.println("Run");
3. Access Mostly Uused Products by 50000+ Subscribers
4. Runnable run => System.out.println("Run");
5. None of above




Correct Answer : Get Lastest Questions and Answer :









Question : You have been given below Java Code

public class Painting {
private String type;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public static void main(String[] args) {
Painting obj1 = new Painting();
Painting obj2 = new Painting();
obj1.setType(null);
obj2.setType("Fresco");
System.out.print(obj1.getType() + " : " + obj2.getType());
}
}

When you run it, what would be printed ?


   : 	You have been given below Java Code
1. : Fresco
2. null : Fresco
3. Access Mostly Uused Products by 50000+ Subscribers
4. A NullPointerException is thrown at runtime




Correct Answer : Get Lastest Questions and Answer :







Related Questions


Question : Given the code fragment:

public class ForTest {
public static void main(String[] args) {
int[] array = { 1, 2, 3 };
for (foo) {
}
}
}

Which three code fragments, when replaced individually for foo, enables the program to compile?

A. int i : array
B. int i = 0; i < 1;
C. ; ;
D. ; i < 1; i++
E. i = 0; i<1;

 : Given the code fragment:
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D,E
5. B,C,E






Question : You have been given following code as below.

public class ComputeSum {
public int x;
public int y;
public int sum;

public ComputeSum(int nx, int ny) {
x = nx;
y = ny;
updateSum();
}

public void setX(int nx) {
x = nx;
updateSum();
}

public void setY(int ny) {
x = ny;
updateSum();
}

void updateSum() {
sum = x + y;
}
}


This class needs to protect changes on the "sum" field. Which three members must have the private access modifier to ensure that this invariant is maintained?

A. The x field
B. The y field
C. The sum field
D. The ComputerSum ( ) constructor
E. The setX ( ) method
F. The setY ( ) method

  : You have been given following code as below.
1. A,B,C
2. B,C,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. A,D,E
5. C,E,F




Question : Which two statements are true?
A. An abstract class can implement an interface.
B. An abstract class can be extended by an interface.
C. An interface CANNOT be extended by another interface.
D. An interface can be extended by an abstract class.
E. An abstract class can be extended by a concrete class.
F. An abstract class CANNOT be extended by an abstract class.
 : Which two statements are true?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. D,F
5. A,E



Question : You have been given below code

package WQ5;

abstract class A1 {
public abstract void m1();

public void m2() {
System.out.println("Green");
}
}

abstract class A2 extends A1 {
public abstract void m3();

public void m1() {
System.out.println("Cyan");
}

public void m2() {
System.out.println("Blue");
}
}

public class A3 extends A2 {
public void m1() {
System.out.println("Yellow");
}

public void m2() {
System.out.println("Pink");
}

public void m3() {
System.out.println("Red");
}

public static void main(String[] args) {
A2 tp = new A3();
tp.m1();
tp.m2();
tp.m3();
}
}

When you run it , what would be result ?


 : You have been given below code
1. Yellow Pink Red
2. Cyan Blue Red
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation Fails




Question : You are writing a method that is declared not to return a value. Which two are permitted in the method body?

A. omission of the return statement
B. return null;
C. return void;
D. return;



 : You are writing a method that is declared not to return a value. Which two are permitted in the method body?
1. A,B
2. A,D
3. Access Mostly Uused Products by 50000+ Subscribers
4. C,D





Question : You have been given below code

import java.util.*;

public class Ref {
public static void main(String[] args) {
StringBuilder s1 = new StringBuilder("Hello Java!");
String s2 = s1.toString();
List lst = new ArrayList();
lst.add(s2);
System.out.println(s1.getClass());
System.out.println(s2.getClass());
System.out.println(lst.getClass());
}
}

When you run it, what would be result ?


 :  You have been given below code
1. class java.lang.String class java.lang.String class java.util.ArrayList
2. class java.lang.Object class java.lang. Object class java.util.Collection
3. Access Mostly Uused Products by 50000+ Subscribers
4. class java.lang.StringBuilder class java.lang.String class java.util.List