Premium

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



Question : Please look into given code fragement.
Which of the following conditional statement will help
you to print Equal ?
  : Please look into given code fragement.
1. String firstString = secondString;
if(firstString==secondString)
2. if(firstString.equlaIgnoreCase(secondString))
3. String thirdString = secondString;
if(firstString.equals(thirdString));
4. if(firstString.toLowerCase() == str2.toLowerCase())



Correct Answer : 2







Question : You have been given below code fragement

StringBuilder sb = new StringBuilder ( ) ;
sb.append ("world");

Which code fragment prints Hello World?

  :   You have been given below code fragement
1. sb.insert(0,"Hello "); System.out.println(sb);
2. sb.append(0,"Hello "); System.out.println(sb);
1. sb.add(0,"Hello "); System.out.println(sb);
2. sb.set(0,"Hello "); System.out.println(sb);




Correct Answer : 1 Exp: The java.lang.StringBuilder.insert(int offset, char c) method inserts the string representation of the char argument into this sequence.
The second argument is inserted into the contents of this sequence at the position indicated by offset. The length of this sequence increases by one.
The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.








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. if (h1 = = h2)
4. if (h1.same(h2))


Correct Answer : 2
Explanation: The equals method compares values for equality








Related Questions


Question : You have been given below code

public class Test {

public static void main(String[] args) {
int numsl[] = new int[3];
int nums2[] = { 1, 2, 3, 4, 5 };
numsl = nums2;
for (int x : numsl) {
System.out.print(x + " : ");
}
}
}

What would be the result?

  : You have been given below code
1. 1:2:3:4:5:
2. 1:2:3:
3. Access Mostly Uused Products by 50000+ Subscribers
4. An ArrayoutofBoundsException is thrown at runtime.




Question : You have been given below code, what would be printed when you run it?

public class Product {
int id;
String name;

public Product(int id, String name) {
this.id = id;
this.name = name;
}

public static void main(String[] args) {

// And given the code fragment:
Product p1 = new Product(101, "Pen");
Product p2 = new Product(101, "Pen");
Product p3 = p1;

boolean ansl = p1 == p2;
boolean ans2 = p1.name.equals(p2.name);
System.out.print(ansl + ":" + ans2);

}
}

 : You have been given below code, what would be printed when you run it?
1. true:true
2. true:false
3. Access Mostly Uused Products by 50000+ Subscribers
4. false:false




Question : Given the following classes:

public class Director extends Manager {
public int stockOptions;
}

public class Manager extends Employee {
public int budget;
}

public class Employee {
public int salary;


public static void main(String[] args) {
Employee employee = new Employee();
Manager manager = new Manager();
Director director = new Director();
// line n1
}
}

Which two options fail to compile when placed at line n1 of the main method?

A. employee.salary = 50_000;
B. director.salary = 80_000;
C. employee.budget = 200_000;
D. manager.budget = 1_000_000;
E. manager.stockOption = 500;
F. director.stockOptions = 1_000;


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




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