Page 1 of 1

find the line that compile..

Posted: Sun Jan 15, 2017 2:55 am
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.....

Re: find the line that compile..

Posted: Fri Feb 17, 2017 2:08 pm
by AndaRO
What is your question?