Grokking Java Interview Questions
Vote

0% completed

​

Predict the Output: Inheritance and Initialization

The statement new Fruit() is short, but it can run code in several places: field initializers, constructors, and methods of two or more classes. The order of these parts is fixed by the language, and so is the choice of every method.

The following six programs test one rule each. For every program, note the value of each field step by step, and write down the output before you run it.

Program 1: A Static Field That Creates an Object

The class Stock creates one of its own objects in its first static field.

<details><summary>Show answer</summary>

**The program prints 0, 50, 1,

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content