Questions1: Given:
public class Triangle { static double area; int b = 2, h = 3; public static void main(String[] args) { double p, b, h; // line1 if (area == 0) { b = 3; h = 4; p = 0.5; area = p * b * h; // line 2 } System.out.println("Area is " + area); } }
What is the result?
A. Area is 6.0
B. Area is 3.0
C. Compilation fails at line1
D.Compilation fails at line2
Answer: A. There wont be any compilation error and p,b,h are confined with local scope and outer variables (b,h) are at Object level and must accessed with Object only like ( triangleObj.b, traingleObj.a)
Questions2: Given:
public class Test { public static void main(String[] args) { int numbers[] = { 12, 13, 42, 32, 15, 156, 23, 51, 12 }; int[] keys = findMaxNumbers(numbers); } /* line n1 */ { int[] keys = new int[3]; /* logic goes here to find max numbers */ return keys; } }
Which method signature do you use at line number n1?
A. public int findMax (int[] numbers)
B. static int[] findMax (int[] max)
C. static int findMax (int[] numbers)
D. final int findMax (int[] )
Answer: C. Explanation: You can not access any method with out object instance in static main method. findMaxNumbers is accessed with out object then method should be defined as static method
Question3: Given the below code:
public class Test { public static void main(String[] args) { int answer; try { int num = 20; int divisor = 0; answer = num / divisor; } catch (ArithmeticException ae) { answer = 0; // line N1 } catch (Exception e) { System.out.println("Invalid division"); } System.out.println("Answer:" + answer);// Line N2 } }
What is the result of above program?
A. Answer = 0
B. Invalid calculation
C. Compilation fails only at line n1.
D. Compilation fails only at line n2.
E. Compilation fails at line n1 and line2
Answer: D: local variables answer must be initialized.
Question 4 : Given the below three Java files
A.java
A.java public class A { public void a() {} int a; } B.Java public class B { private int doStuff() { private int x = 100; return x++; } } C.Java in package : p1 import java.io.* package p1; public class C { public static void main(String[] args) {} }
Which of the below options are correct
A. Only the A.Java file compiles successfully.
B. Only the B.java file compiles successfully.
C. Only the C.java file compiles successfully.
D. The A.Java and B.java files compile successfully.
E. The B.java and C.java files compile successfully.
F. The A.Java and C.java files compile successfully.
Answer: A : Only A.java files compiles successfully. You can see the explanation as below
Question5: What is the result of the below program?
public static void main(String[] args) { String arr[] = {"Hi","How", "Are" ,"you"}; List<String> list = new ArrayList<>(Arrays.asList(arr)); if(list.removeIf( (String s) -> (return s.length()<2;))) { System.out.println(s+" -- Removed"); } }
A. Compilation fails.
B. Hi removed
C. An UnsupportedOperationException is thrown at runtime.
D. The program compiles, but it prints nothing.
Answer: A
Explanation: removeIf requires predicate function, but in the above method there are two errors:
- Invalid predicate funciton
- variable s is not accessible in side if loop.
public static void main(String[] args) { String arr[] = {"Hi","How", "Are" ,"you"}; List<String> list = new ArrayList<>(Arrays.asList(arr)); if(list.removeIf(s-> s.length()<3)) { System.out.println("updated list"+list); } Output: updated list[How, Are, you]
One thought on “Java SE8 Programmer 1z0-808 dumps”
Comments are closed.
Nice collection of Java certification dumps. Thanks for sharing this with us