find the line that compile..

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
sulakshana
Posts: 14
Joined: Thu Dec 22, 2016 8:55 pm
Contact:

find the line that compile..

Post by sulakshana »

package my.school;
2: public class Classroom {
3: private int roomNumber;
4: protected String teacherName;
5: static int globalKey = 54321;
6: public int floor = 3;
7: Classroom(int r, String t) {
8: roomNumber = r;
9: teacherName = t; } }

1: package my.city;
2: import my.school.*;
3: public class School {
4: public static void main(String[] args) {
5: System.out.println(Classroom.globalKey);
6: Classroom room = new Classroom(101, ""Mrs. Anderson");
7: System.out.println(room.roomNumber);
8: System.out.println(room.floor);
9: System.out.println(room.teacherName); } }

in this question in main method only line 8 will compile.....But line 8 is in a static context in main method....
so can it call instance variable floor in the school package....
but only given answer by the book states that only line 8 will compile in main method.....

AndaRO
Posts: 31
Joined: Wed Feb 08, 2017 5:42 pm
Contact:

Re: find the line that compile..

Post by AndaRO »

What is your question?

Post Reply

Who is online

Users browsing this forum: marpiva and 32 guests