nerdexam
Oracle

1Z0-809 · Question #231

Which class definition compiles?

The correct answer is B. ```java class Computer { private Card sCard = new SoundCard(); private abstract class Card { } private class SoundCard extends Card { } } ```. Option B compiles because it correctly uses a private abstract member class (Card) as a type, with a concrete private inner class (SoundCard) that extends it - all at the member level of the outer class, where access modifiers and inheritance are fully permitted. Option A fails…

Question

Which class definition compiles?

Options

  • A
    class Vehicle {
     int id;
     public void start() {
     public class Engine { int eNo = id; }
     }
    }
    
  • B
    class Computer {
     private Card sCard = new SoundCard();
     private abstract class Card { }
     private class SoundCard extends Card { }
    }
    
  • C
    class Block {
     int bNo;
     static class Counter {
     int locator;
     Counter() { locator = bNo; }
     }
    }
    
  • D
    class Product {
     interface Moveable { void move(); }
     Moveable mProduct = new Moveable() {
     void move() { }
     };
    }
    

How the community answered

(62 responses)
  • A
    10% (6)
  • B
    71% (44)
  • C
    16% (10)
  • D
    3% (2)

Explanation

Option B compiles because it correctly uses a private abstract member class (Card) as a type, with a concrete private inner class (SoundCard) that extends it - all at the member level of the outer class, where access modifiers and inheritance are fully permitted.

Option A fails because local classes (defined inside a method body) cannot have access modifiers like public - that keyword is illegal in that context.

Option C fails because static nested classes have no reference to an outer instance, so bNo (an instance field of Block) is inaccessible from the static Counter class.

Option D fails because the anonymous class implements the Moveable interface but declares move() without the public modifier - interface methods are implicitly public, and you cannot reduce visibility when overriding, so the compiler rejects it.

Memory tip: Think "SPAM" - Static nested classes can't see instance fields, Public is required when implementing interface methods, Access modifiers are banned on local classes. If a choice violates any of these, it won't compile.

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice