25 lines
664 B
Java
25 lines
664 B
Java
public class P23 {
|
|
private String parentVariable = "Parent";
|
|
|
|
public void parentMethod() {
|
|
System.out.println("Parent method");
|
|
Child child = new Child();
|
|
child.childMethod();
|
|
}
|
|
|
|
public class Child {
|
|
private String childVariable = "Child";
|
|
|
|
public void childMethod() {
|
|
System.out.println("Child method");
|
|
System.out.println("Accessing parent variable: " + parentVariable);
|
|
System.out.println("Accessing child variable: " + childVariable);
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
P23 parent = new P23();
|
|
parent.parentMethod();
|
|
}
|
|
}
|