<%@ page language="java" contentType="text/html; charset=GBK"%>
<%!interface animal //定义一个接口
{
public abstract char getsound();
}
class mouse implements animal
{
public char sound;
public mouse(){
sound='a';
}
public char getsound(){
return sound;
}
}
class cat implements animal
{
public char sound;
public cat(){
sound='b';
}
public char getsound(){
return sound;
}
}%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>interface</title>
</head>
<body>
<br>创建相应类的对象,执行对象的getsound()方法<br>
<%
char i,j;
mouse m=new mouse();
cat c=new cat();
i=m.getsound();
j=c.getsound();
out.print("<br>cat的sound:"+i);
out.print("<br>mouse的sound:"+j);
%>
</body>
</html>
![]()