package demo; public class Foo { private int result = 20; protected int getResult(){ return result; } }
package test; import demo.Foo; public class Bar extends Foo{ private int sum = 10; public void reportSum(){ sum += getResult(); System.out.println("Sum :" + sum ); } }
public class Demo { public static void main(String[] args){ Bar abc = new Bar(); abc.reportSum(); } }