Questions Related to java

Multiple choice java
  1. The code will compile without changes.

  2. The code will compile if public Tree() { Plant(); } is added to the Tree class.

  3. The code will compile if public Plant() { Tree(); } is added to the Plant class.

  4. The code will compile if public Plant() { this("fern"); } is added to the Plant class.

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice java
  1. int Long

  2. Short Long

  3. Compilation fails.

  4. An exception is thrown at runtime.

Reveal answer Fill a bubble to check yourself
A Correct answer
Multiple choice java
  1. Change line 2 to: public int a;

  2. Change line 2 to :protected int a;

  3. Change line 13 to :public Sub() { this(5); }

  4. Change line 13 to :public Sub() { super(5); }

Reveal answer Fill a bubble to check yourself
C,D Correct answer
Multiple choice java
  1. foofoofoofoofoo

  2. foobarfoobarbar

  3. foobarfoofoofoo

  4. foobarfoobarfoo

  5. barbarbarbarbar

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice java
  1. An encapsulated, public class promotes re-use.

  2. Classes that share the same interface are always tightly encapsulated.

  3. An encapsulated class allows subclasses to overload methods, but does NOT allow overriding methods.

  4. An encapsulated class allows a programmer to change an implementation without affecting outside code.

Reveal answer Fill a bubble to check yourself
A,D Correct answer
Multiple choice java
  1. The class is fully encapsulated.

  2. The code demonstrates polymorphism.

  3. The ownerName variable breaks encapsulation.

  4. The cardID and limit variables break polymorphism.

  5. The setCardInformation method breaks encapsulation.

Reveal answer Fill a bubble to check yourself
C Correct answer