Given:
public class Book {
private String read(String bname) {
return "Read" + bname;
}
}
public class EBook extends Book {
public String read(String url) {
return "View" + url;
}
}
public class Test {
public static void main(String[] args) {
Book b1 = new Book();
b1.read("Java Programing");
Book b2 = new EBook();
b2.read("http://ebook.com/ebook");
}
}
What is the result?
A.
Read Java Programming
View http://ebook.com/ebook
B.
View http://ebook.com/ebook
Read Java Programming
Read http://ebook.com/ebook
C. The EBook.java file fails to compile.Read http://ebook.com/ebook
D. The Test.java file fails to compile.
題解
Test類別會編譯失敗,因為Book物件的read方法是private可見度,第5行和第7行都會編譯失敗。