题生手求问
题新手求问本帖最后由 a3553900 于 2013-08-29 00:08:53 编辑abstract class Fu{abstract public void sha
题新手求问
本帖最后由 a3553900 于 2013-08-29 00:08:53 编辑
abstract class Fu
{
abstract public void shangke();
public void chouyan(){};
public void hejiu(){};
}
class Zi extends Fu
{
public void shangke()
{
System.out.println("xiaoxue");
}
public void chouyan(String a)
{
System.out.println(a);
}
}
class Zi1 extends Fu
{
public void shangke()
{
System.out.println("chuzhong");
}
public void hejiu()
{
System.out.println("喝酒");
}
}
class ceshi
{
public static void main(String[] args)
{
shang(new Zi());//怎么才把字符传到Zi的chouyan方法里面去呢?
}
public static void shang(Fu a)
{
if(a instanceof Zi)
{
a.chouyan();
}
else if(a instanceof Zi1)
{
a.hejiu();
}
}
}
[解决办法]public static void shang(Fu a)
{
if(a instanceof Zi)
{
a.chouyan("在这里添加字符串");
}
调重载的方法啊