Premium

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



Question : Which code fragment, when inserted at line n,
enables the code to print Harish?
  : Which code fragment, when inserted at line n,
1. checkAge (iList, ( ) -> p. get Age () > 40);
2. checkAge(iList, Person p -> p.getAge() > 40);
3. checkAge (iList, p -> p.getAge() > 40);
4. checkAge(iList, (Person p) -> { p.getAge() > 40; });



Correct Answer : 3
Explanation:





Question : Given the code snippet :

When you run this code, what will be printed

  : Given the code snippet :
1. X Y Z
2. X Y Z P Q
3. X Y P Q
4. Compilation Error


Correct Answer : 3
Explanation:








Question : Please look into , given code fragement.
Select the correct options which will be printed out.

  : Please look into , given code fragement.
1. true true
2. true false
3. false false
4. false true



Correct Answer : 3

Explanation:




Related Questions


Question : You have been given below code

public class Triangle {
static double area;
int b = 2, h = 3;

public static void main(String[] args) {
double p, b, h; // line n1
if (area == 0) {
b = 3;
h = 4;
p = 0.5;
}
area = p * b * h; // line n2
System.out.println("Area is " + area);
}
}

What is the result?

  : You have been given below code
1. Area is 6.0
2. Area is 3.0
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails at line n2





Question : Given the code fragment:

public class Test {
public static void main(String[] args) {
// line n1
switch (x) {
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;

}
}
}

Which three code fragments can be independently inserted at line nl to enable the code to print one?

A. Byte x = 1;
B. short x = 1;
C. String x = "1";
D. Long x = 1;
E. Double x = 1;
F. Integer x = new Integer ("1");

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



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

public class App {
public static void main(String[] args) {
Boolean[] bool = new Boolean[2];
bool[0] = new Boolean(Boolean.parseBoolean("true"));
bool[1] = new Boolean(null);
System.out.println(bool[0] + " " + bool[1]);
}
}



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

4. A NullPointerException is thrown at runtime




Question : You have been given two separate classes as below.

public class MyException extends RuntimeException { }

public class Test {
public static void main(String[] args) {
try {
method1();
} catch (MyException ne) {
System.out.print("A");
}
}

public static void method1() { // line n1
try {
throw Math.random() > 0.5 ? new MyException()
: new RuntimeException();
} catch (RuntimeException re) {
System.out.print("B");
}
}
}

What is the result?

 : You have been given two separate classes as below.
1. A
2. B
3. Access Mostly Uused Products by 50000+ Subscribers
4. AB
5. A compile time error occurs at line n1





Question : You have been given Java Application as below code

public class App {
String myStr = "7007";

public void doStuff(String str) {
int myNum = 0;
try {
String myStr = str;
myNum = Integer.parseInt(myStr);
} catch (NumberFormatException ne) {
System.err.println("Error");
}
System.out.println("myStr: " + myStr + ", myNum: " + myNum);
}

public static void main(String[] args) {
App obj = new App();
obj.doStuff("9009");
}
}

What happen/print, when you execute this code ?

  : You have been given Java Application as below code
1. myStr: 9009, myNum: 9009
2. myStr: 7007, myNum: 7007
3. Access Mostly Uused Products by 50000+ Subscribers
4. Compilation fails





Question : Which two are benefits of polymorphism?
A. Faster code at runtime
B. More efficient code at runtime
C. More dynamic code at runtime
D. More flexible and reusable code
E. Code that is protected from extension by other classes

 : Which two are benefits of polymorphism?
1. A,B
2. B,C
3. Access Mostly Uused Products by 50000+ Subscribers
4. C,D
5. A,E