如何在 Java 中编写接口名称?


编写接口/类名称时,你需要记住以下几点。

  • 接口/类名称的首字母应大写,其余字母应小写(混合大小写)。
interface Sample
  • 同样,名称中每个单词的首字母都应大写,其余字母应小写。
interface MYInterface
  • 建议保持接口名称简单且有描述性。
  • 最好不要在编写接口/类名称时使用缩写词。

示例

实时演示

interface MyInterface { 
   void sample();
   void demo();
}
public class Test implements MyInterface {
   public void sample() {
      System.out.println("This is sample method");   
   }
   public void demo() {
      System.out.println("This is demo method");   
   }
   public static void main(String args[]) {
      Test obj = new Test();
      obj.sample();
      obj.demo();
   }
}

输出

This is sample method
This is demo method

更新于: 30-7-2019

591 次浏览

开启您的 职业生涯

完成课程以获得认证

开始
广告
© . All rights reserved.