STRUCTURE
src
├── pkg
│ ├── subpkg1
│ │ └── restaurant.java
│ ├── subpkg2
│ ├── H.java
│ └── test2.java
file name= restaurant.java
package pkg.subpkg1;
public class restaurant {
public String name = "Domino";
protected void open() {
System.out.println("The restaurant is open");
}
}
file name= H.java
package pkg.subpkg2;
import pkg.subpkg1.restaurant;
public class H extends restaurant {
}
file name= test2.java
package pkg.subpkg2;
public class test2 {
public static void main(String[] args) {
H r1 = new H();
r1.open();
System.out.println(r1.name);
}
}
Error: open() has protected access in restaurant
I expect that i will be able to get the “open” method from the instance of H class
AMITESH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.