I have two classes in different packages as follows. This is the base class in the package library.
package library;
public class Book{
public int varPublic;
protected int varProtected;
private int varPrivate;
int varDefault;
}
and this is a subclass in package building.
package building;
import library.Book;
public class StoryBook extends Book {
public static void main(String[] args) {
Book book = new Book();
book.varPublic = 10;
book.varProtected = 11;
}
}
I understand that the variable "var.Protected" should be visible in the StoryBook class, but I get an error message. I tried to execute this code from eclipse and command line.
can anyone look at this
source
share