30 java program skills questions(1)


本题来自30 Java Coding Questions To Assess Programming Skills,该网站在Java开发者都爱用的11个网站中都介绍过,可以多加利用。

Question-1

Which Of The Following Would The Below Java Coding Snippet Return As Its Output?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class  {
public int index = 1;
}

class App extends {

public App(int index) {
index = index;
}

public static void main(String args[]) {
App myApp = new App(10);
System.out.println(myApp.index);
}
}

A. 0
B.10
C.1
D.Compile time error

Question-2

Which Of The Following Combinations Would The Below Java Coding Snippet Print?

1
2
3
4
5
6
7
8
9
10
class TestApp {
protected int x, y;
}

class Main {
public static void main(String args[]) {
TestApp app = new TestApp();
System.out.println(app.x + " " + app.y);
}
}