Java⼩⽩interface与implements创建⽼师类和学⽣类,两个类都实现了问候。
。。
solver;
interfaceGreetings//问候接⼝
{
voidsay();
}
interfacework//⼯作接⼝
{
voidsay1();
}
classStudentimplementsGreetings
{
publicvoidsay()
{
n("peter:⽼师好");
}
}
classTeacherimplementsGreetings
{
publicvoidsay()
{
n("mike:同学们好");
}
}
classStudent1implementswork
{
publicvoidsay1()
{
n("mike:⽼师开始上课");
}
}
classTeacher1implementswork
{
publicvoidsay1()
{
n("peter:⽼师开始记笔记");
}
}
classMain
{
publicstaticvoidmain(String[]args)
{
Greetings[]says={newStudent(),newTeacher()};
work[]says1={newStudent1(),newTeacher1()};
for(inti=0;i<;i++)
{
says[i].say();
}
for(inti=0;i<;i++)
{
says1[i].say1();
}
}
}
本文发布于:2022-12-31 22:31:57,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/90/68235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |