Interface (以及java代码书写规范)
C++: | 继承 | 组合 |
JAVA: | 继承 | 接口 |
| 核心 | 插件 |
java代码书写规范:
花括号前加1个空格; {
变量名小写;name,age;
常量名大写;final int AINF_X
函数名小写开头;ainf_m1
类名称大写开头;Binf
函数名、类名等名称的后继的字母头大写;openDoor,interface NetWorkCard;
/*______________________________________________________________________________*/
package com.fs.test;
public interface Ainf {
public static final int AINF_X = 34; //public static final 类型 变量名=值 //public static final不写也是自动的
public int AINF_Y= 234;
public abstract void ainf_m1(); //public abstract 返回类型 函数名(参数) //public abstract 不写也是自动的
void ainf_m2();
}
/*______________________________________________________________________________*/
package com.fs.test;
public interface Binf {
public void binf_m1();
public void binf_m2();
}
/*______________________________________________________________________________*/
package com.fs.other;
import com.fs.test.Ainf;
import com.fs.test.Binf;
public class Test implements Ainf,Binf {
@Override
public void binf_m1() {
System.out.println("binf_m1()");
//接口的方法都是抽象的,都要重写。少写一个就要错,这与抽象方法的继承类似。接口不是继承。
}
@Override
public void binf_m2() {
System.out.println("binf_m2()");
}
@Override
public void ainf_m1() {
System.out.println("ainf_m1()");
}
@Override
public void ainf_m2() {
System.out.println("ainf_m2()");
}
public static void main(String[] args) {
Test test = new Test();
test.ainf_m1();//ainf_m1()
test.ainf_m2();//ainf_m2()
test.binf_m1();//binf_m1()
test.binf_m2();//binf_m2()
System.out.println(Ainf.AINF_X);//34//public static final int AINF_X = 34;常量
System.out.println(Ainf.AINF_Y);//234
System.out.println(test.AINF_X);//34
System.out.println(test.AINF_Y);//234
System.out.println(Test.AINF_X);//34
System.out.println(Test.AINF_Y);//234
}
}
以上是 Interface (以及java代码书写规范) 的全部内容, 来源链接: utcz.com/z/391380.html