nerdexam
Oracle

1Z0-804 · Question #30

Which statement declares a generic class?

The correct answer is A. public class Example < T > { }. public class Pocket<T> private T value; public Pocket() {} public Pocket( T value ) { this.value = value; } public void set( T value ) { this.value = value; } public T get() { return value; } public boolean isEmpty() { return value != null; } public void empty() { value = null; }

Generics and Collections

Question

Which statement declares a generic class?

Options

  • Apublic class Example < T > { }
  • Bpublic class <Example> { }
  • Cpublic class Example <> { }
  • Dpublic class Example (Generic) { }
  • Epublic class Example (G) { }
  • Fpublic class Example { }

How the community answered

(40 responses)
  • A
    85% (34)
  • D
    5% (2)
  • E
    3% (1)
  • F
    8% (3)

Explanation

public class Pocket<T> private T value; public Pocket() {} public Pocket( T value ) { this.value = value; } public void set( T value ) { this.value = value; } public T get() { return value; } public boolean isEmpty() { return value != null; } public void empty() { value = null; }

Topics

#generic class#type parameter syntax#generics declaration#bounded types

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice