java编写一个有关接口的程序

如题所述

public
interface

-----------接口;
{
public
void
吃饭();----------
接口中的方法;
}
---------------------------------
接口的实现类;
public
class
男人
implements

{
public
void
吃饭()
------它实现了上面的接口,它就必
-----需实现上面的方法;
{
System.out.println("真好吃");
}
public
void
挣钱()
------在实现类中还可以写自己的方法
{
System.out.println("真累啊");
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-04-19
有如下两个接口,定义一个类实现下面两个接口.
interface
studentInfo
{
int
year=2007;
int
age();
void
showInfo();
}
interface
studentScore
{
float
total();
float
ave();
}
这个类实现上述两个接口
public
class
Student
implements
studentInfo,
studentScore
{
int
age()
{
//方法内容省略
}
void
showInfo()
{
//方法内容省略
}
float
total()
{
//方法内容省略
}
float
ave()
{
//方法内容省略
}
}