1~

Minter Coder's Blog

Chapter 1 - Soru 12

2021-03-17

12. What is the result of compiling and executing the following class?
1: public class ParkRanger {
2:int birds = 10;
3:public static void main(String[] data) {
4:int trees = 5;
5:System.out.print(trees+birds);
6:}
7: }
A. It does not compile.
B. It compiles but throws an exception at runtime.

C. It compiles and outputs 5 .
D. It compiles and outputs 15 .

Öncelikle birds bizim nesne değişkenimiz (instance variable) buna erişme için öncelikle instance of a ParkRanger , yani ParkRanger sınıfının bir nesnesini oluşturmamız gerekiyor , ki , kendisi oluşturmadan birds'e erişmeye çalışıp toplamaya çalışmış , hata! Kod derlenmez.