Java Reference
In-Depth Information
5.
Given the following class definition:
1. public class Television {
2. private int channel = setChannel(7);
3.
4. public Television(int channel) {
5. this.channel = channel;
6. System.out.print(channel + “ “);
7. }
8.
9. public int setChannel(int channel) {
10. this.channel = channel;
11. System.out.print(channel + “ “);
12. return channel;
13. }
14.}
what is the output of the following statement?
new Television(12);
A.
12
B.
12 7
C.
7 12
D.
7
E.
The code does not compile.
6.
Given the following my.school.ClassRoom and my.city.School class definitions:
1. //ClassRoom.java
2. package my.school;
3. public class ClassRoom {
4. private int roomNumber;
5. protected String teacherName;
6. static int globalKey = 54321;
7.
8. ClassRoom(int r, String t) {
9. roomNumber = r;
10. teacherName = t;
11. }
12. }
//School.java
Search WWH ::
Custom Search