Sample Questions for java exam , Study notes of Java Programming

1Z0-808 - Java SE 8 Programmer I sample questions

Typology: Study notes

2016/2017

Uploaded on 09/09/2017

prakash4194
prakash4194 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Exam 808: Java SE 8
1. Given:
import java.util.ArrayList;
import java.util.List;
public class JavaSETest {
public static void main(String[] args) {
List<Integer> elements = new ArrayList<>();
elements.add(10);
int firstElmnt = elements.get(1);
System.out.println(firstElmnt);
}
}
What is the result?
A) null
B) 10
C) 0
D) An IndexOutOfBoundsException is thrown at runtime.
2. Given the code fragment:
// Line n1
switch (cardVal) {
case 4: case 5: case 6:
case 7: case 8:
System.out.println("Hit");
break;
case 9: case 10: case 11:
System.out.println("Double");
break;
case 15: case 16:
System.out.println("Surrender");
break;
default:
System.out.println("Stand");
}
Which two code fragments can be inserted at Line n1, independently, enable to print Stand?
A) int cardVal = 6;
B) int cardVal = 10;
C) int cardVal = 14;
D) int cardVal = 18;
pf3
pf4

Partial preview of the text

Download Sample Questions for java exam and more Study notes Java Programming in PDF only on Docsity!

Exam 808: Java SE 8

  1. Given:

import java.util.ArrayList; import java.util.List;

public class JavaSETest { public static void main(String[] args) { List elements = new ArrayList<>(); elements.add(10); int firstElmnt = elements.get(1); System.out.println(firstElmnt); } }

What is the result?

A) null B) 10 C) 0 D) An IndexOutOfBoundsException is thrown at runtime.

  1. Given the code fragment:

// Line n switch (cardVal) { case 4: case 5: case 6: case 7: case 8: System.out.println("Hit"); break; case 9: case 10: case 11: System.out.println("Double"); break; case 15: case 16: System.out.println("Surrender"); break; default: System.out.println("Stand"); }

Which two code fragments can be inserted at Line n1, independently, enable to print Stand?

A) int cardVal = 6; B) int cardVal = 10; C) int cardVal = 14; D) int cardVal = 18;

  1. Given:

abstract class Writer { public static void write() { System.out.println("Writing..."); } } class Author extends Writer { public static void write() { System.out.println("Writing book"); } } public class Programmer extends Writer { public static void write() { System.out.println("Writing code"); } public static void main(String[] args) { Writer w = new Programmer(); w.write(); } }

What is the result?

A) Writing... B) Writing book C) Writing code D) Compilation fails.

  1. Given:

class SuperClass { SuperClass(int x) { System.out.println("Super"); } }

public class SubClass extends SuperClass { SubClass() { // Line n System.out.println("Sub 2"); } }

Which statement, when inserted at Line n1, enables the code to compile?

A) this(10); B) super(10); C) SuperClass(10); D) super.SuperClass (10);

  1. Given the code fragment:

public class Test { public static void main(String[] args) { int x = 10; int y = 2; try { for (int z = 2; z >= 0; z--) { int ans = x / z; System.out.print(ans+ " "); } } catch (Exception e1) { System.out.println("E1"); } catch (ArithmeticException e1) { System.out.println("E2"); } } }

What is the result?

A) E B) E C) 5 10 E D) Compilation fails.

  1. Given the code fragment:

StringBuilder s1 = new StringBuilder("Java"); String s2 = "Love"; s1.append(s2); s1.substring(4); int foundAt = s1.indexOf(s2); System.out.println(foundAt);

What is the result?

A) - B) 3 C) 4 D) A StringIndexOutOfBoundsException is thrown at runtime.

Answers:

1) D

  1. C and D
  2. A
  3. B
  4. C
  5. B
  6. D
  7. C