大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
interface Bike{
我们提供的服务有:成都做网站、网站建设、微信公众号开发、网站优化、网站认证、祁门ssl等。为1000多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的祁门网站制作公司
public void radio();
}
interface Car{
public void tv();
}
interface Dt{
public void music();
}
public class InterfaceDemo implements Bike,Car,Dt{
public void radio() {
System.out.println("可以听广播");
}
public void tv() {
System.out.println("可以看电视");
}
public void music() {
System.out.println("可以听音乐");
}
public static void main(String args[])
{
InterfaceDemo m=new InterfaceDemo();
m.radio();
m.tv();
m.music();
}
}
非常简单,基础语法:
public interface 接口名 {
常量定义;
抽象方法定义;
default 方法定义;
}
即使你在接口中不定义任何方法,也是可以的。
//Muitiplication接口
public interface Muitiplication{
double mult(double a, double b);
}
//MuitiplicationImpl实现类
public class MuitiplicationImpl implements Muitiplication{
public double mult(double a, double b){
return a * b;
}
}
//MuitiplicationImpls实现类
public class MuitiplicationImpls implements Muitiplication{
public double mult(double a, double b){
return a + b;
}
}
public static void main(args[]){
MuitiplicationImpl m = new MuitiplicationImpl();
System.out.println(m.mult(1.001,1.001));
MuitiplicationImpls ms = new MuitiplicationImpls();
System.out.println(ms.mult(1.001,1.001));
}
interface l1 { abstract void test(int i); } interface l2 { abstract void test(String s); } public class jiekou implements l1,l2 { public void test(int i) { System.out.println("接口1"); } public void test(String s) { System.out.println("接口2"); } public static void main(String args[]) { jiekou t=new jiekou(); t.test(42); t.test("Hello"); } } 下一个是内部接口 public class groupsix { public interface student_info { public void out(); } public class student implements student_info { int count; String name; public student(String n1) { name=n1; count++; } public void out() { System.out.println(this.name+" count="+this.count); } } public groupsix(String name1[]) { student s1; int i=0; while(iname1.length) { s1=new student(name1[i]); s1.out(); i++; } } public static void main(String args[]) { String arr[]={"A","B","C"}; groupsix g6; new groupsix(arr); } }