クラスの中のクラスの中のメソッドの使い方はありますか?
専門学校の授業でインターフェースを習っているのですが、わからないことがあります。
xecuter e3 = new Executer(new Sales());のe3でSalesの中のaddSaleとaddcountを使う方法がありましたら知りたいです
解決方法を教えてください!
該当のソースコード
interface Printable{ public abstract void show(); } class Student implements Printable{ private String _name; private String _address; public Student(String n,String a){ _name = n; _address = a; } public void show(){ Class c = getClass(); String name = c.getName(); System.out.println(name+":"+_name+" "+_address); } } class Product implements Printable{ private String _name; private int _price; public Product(String n,int p){ _name = n; _price = p; } public void show(){ Class c = getClass(); String name = c.getName(); System.out.println(name+":"+_name+" "+_price); } } class Sales implements Printable{ private int _sale; private int _count; public void addSale(int s){ _sale+=s; } public void addCount(int c){ _count+=c; } public void show(){ Class c = getClass(); String name = c.getName(); System.out.println(name+":"+_sale+" "+_count); } } class Executer{ private Printable p; public Executer(Printable p){ this.p = p; } public void showMeth(){ p.show(); } } class sample{ public static void main(String[]args){ Executer e1 = new Executer(new Student("尾崎豊","東京都")); Executer e2 = new Executer(new Product("尾崎豊",12345)); Executer e3 = new Executer(new Sales()); e1.showMeth(); e2.showMeth(); e3.showMeth(); } }
試したこと
Salesの中のaddSaleとaddcountを使いたいです!