java中为按钮添加图片

No, it is not possible to define private and protected modifiers for the members in interfaces in Java.

不可以,无法为Java接口中的成员定义私有修饰符和受保护的修饰符。

  • As we know that, the members defined in interfaces are implicitly public or in other words, we can say the member defined in an interface is by default public.

    众所周知,接口中定义的成员是隐式公共的,换句话说,我们可以说接口中定义的成员默认是公共的。

  • It is possible to define public modifiers for the member in interfaces.

    可以在接口中为该成员定义公共修饰符。

  • In the case of public modifiers, it is not mandatory to prefix "public" with members in interfaces because all the members of the interface are by default public.

    对于public修饰符,由于接口的所有成员默认情况下都是public,因此在接口中的成员之前不必强制给“ public”加上前缀。

  • We will discuss three cases in terms of modifiers for the members in interfaces.

    我们将针对接口中成员的修饰符讨论三种情况。

    1. What will happen, if we define private modifiers for the members in an interface?
    2. What will happen, if we define protected modifiers for the members in the interface?
    3. What will happen, if we define public modifiers for the members in the interface?
    4. What will happen, if we define no modifiers for the members in the interface?

We will see each of the above cases one by one with the help of an example...

在示例的帮助下,我们将逐一看到上述每种情况。

1)在Java接口中为成员定义私有修饰符 (1) Defining private modifiers for the member in interface in Java)

// Java program to demonstrate the example of
// defining private members for the interface
interface PrivateMemberInterface {private String str = "There will be an error.";
void display();
}
public class Main implements PrivateMemberInterface {// override display() of PrivateMemberInterface
public void display() {System.out.print("Private modifiers not allowed");
System.out.print("for Data Members");
}
public static void main(String[] args) {// class instantiation
Main m = new Main();
// calling display() of Main class
m.display();
// Accessing private member of an interface
System.out.println(str);
}
}

Output

输出量

/Main.java:5: error: modifier private not allowed hereprivate String str = "There will be an error.";^
1 error

Conclusion: We cannot define private modifiers for the members in interface.

结论:我们不能为接口中的成员定义私有修饰符。

2)在Java接口中为成员定义受保护的修饰符 (2) Defining protected modifiers for the member in interface in Java)

// Java program to demonstrate the example of
// defining protected members for the interface
interface ProtectedMemberInterface {protected String str = "There will be an error.";
void display();
}
public class Main implements ProtectedMemberInterface {// override display() of ProtectedMemberInterface
public void display() {System.out.print("Protected modifiers not allowed");
System.out.print("for Data Members");
}
public static void main(String[] args) {// class instantiation
Main m = new Main();
// calling display() of Main class
m.display();
// Accessing protected member of an interface
System.out.println(str);
}
}

Output

输出量

/Main.java:5: error: modifier protected not allowed hereprotected String str = "There will be an error.";^
1 error

Conclusion: We cannot define protected modifiers also for the members in interface.

结论:我们也不能为接口中的成员定义受保护的修饰符。

3)在Java接口中为成员定义公共修饰符 (3) Defining public modifiers for the member in interface in Java)

// Java program to demonstrate the example of
// defining public members for the interface
interface PublicMemberInterface {public String str = "No error here...";
void display();
}
public class Main implements PublicMemberInterface {// override display() of PublicMemberInterface
public void display() {System.out.print("Public modifiers are allowed" + " ");
System.out.print("for Data Members");
}
public static void main(String[] args) {// class instantiation
Main m = new Main();
// calling display() of Main class
m.display();
System.out.println();
// Accessing public member of an interface
System.out.println(str);
}
}

Output

输出量

Public modifiers are allowed for Data Members
No error here...

Conclusion: We can define public modifiers for the members in an interface and it is valid in java.

结论:我们可以为接口中的成员定义公共修饰符,并且在Java中有效。

4)在Java接口中未为成员定义任何修饰符 (4) Not defining any modifiers for the member in interface in Java)

// Java program to demonstrate the example of
// not defining any modifier for the members in
// interface
interface NoModifierMemberInterface {String str = "No error here...";
void display();
}
public class Main implements NoModifierMemberInterface {// override display() of NoModifierMemberInterface
public void display() {System.out.print("No modifiers are allowed" + " ");
System.out.print("for Data Members");
}
public static void main(String[] args) {// class instantiation
Main m = new Main();
// calling display() of Main class
m.display();
System.out.println();
// Accessing no modifiers member of an interface
System.out.println(str);
}
}

Output

输出量

No modifiers are allowed for Data Members
No error here...

Conclusion: We can define no modifiers for the members in the interface and it is valid in java because by default modifier for the member is public.

结论:我们无法在接口中为成员定义修饰符,并且在Java中是有效的,因为默认情况下,该成员的修饰符是公共的。

翻译自: https://www.includehelp.com/java/can-we-define-private-and-protected-modifiers-for-the-members-in-interfaces-in-java.aspx

java中为按钮添加图片

java中为按钮添加图片_我们可以在Java接口中为成员定义私有和受保护的修饰符吗?...相关推荐

  1. java中为按钮添加图片_如何在Java中为字符串添加双引号?

    java中为按钮添加图片 In Java, everything written in double-quotes is considered a string and the text writte ...

  2. android添加图片按钮,如何给Android中的按钮添加图片功能

    在layout中建一个my_login.xml文件 代码如下 android:layout_width="fill_parent" android:layout_height=&q ...

  3. MFC中 给按钮添加图片的方法

    方法一:直接给CButton加图片. 1.在资源编辑器中添加一个按钮,把它的Bitmap属性设为true 2.在按钮上点右键,添加一个变量m_Btn(CButton类型的) 3.将图片导入到资源管理器 ...

  4. Qt中为工程添加资源文件、给按钮添加图片

    Qt中为工程添加资源文件.给按钮添加图片 1.使用QIcon类.代码如下: QIcon icon;icon.addFile(tr("res/icon/wall.png"));ui- ...

  5. java中文件处理之图片_在Java 7中处理文件

    java中文件处理之图片 以下是The Well-Grounded Java Developer的草稿的修改后的片段. 它使您快速了解与以前版本相比,在Java 7中操作文件要容易得多. 通过使用新的 ...

  6. UITableViewCell 左侧滑动删除按钮 添加图片 (不完美解决)

    *需求:给cell左侧滑动删除按钮添加图片 //目前的解决方法 链接: https://pan.baidu.com/s/1kVE5gMF 密码: zaph *装态:还在解决 网上查过资料一直没好的解决 ...

  7. ivew的Table中使用render添加图片poptip冒泡方法

    效果 ivew的Table中使用render添加图片poptip冒泡方法 {title: '操作',key: 'action',width: 120,align: 'center',render: ( ...

  8. java中接口私有反方_Java 8:在接口中声明私有和受保护的方法

    java中接口私有反方 引入Java 8时,我们可以在接口中使用默认方法. 此功能的主要驱动程序是允许接口扩展,同时保留对旧接口版本的向后兼容性. 一个示例是在现有Collection类中引入stre ...

  9. php 受保护类,php中如何在外部修改类的私有或受保护属性值

    php中怎么在外部修改类的私有或受保护属性值 在做单元测试框架时,发现了个比较郁闷的问题:测试人员需要在类外修改类的private或protected成员变量的值,而这些变量没有抽象成public的属 ...

最新文章

  1. 顺序队列之C++实现
  2. 京东DNN Lab首席科学家:用深度学习搞定80%的客服工作
  3. Hadoop Hive替换自带的derby数据库为MySQL具体步骤
  4. python加载模型文件进行图片分类_tensorflow通过模型文件,使用tensorboard查看其模型图Graph方式...
  5. jzoj4672-Graph Coloring【图论,模拟】
  6. SAP 采购流程和销售流程
  7. python哪个国家的品牌_Python之初识Web,打造属于你的个人品牌!
  8. 理解Marx-4 马克思的第一次思想转变
  9. 《云计算:原理与范式》一3.2 知识经济时代的来临
  10. java去除以张开头的人名_写出java8实现对ListUser中的username字段过滤出不等于张三的数据...
  11. JAVA 基础语法(五)——数组
  12. verilog中~在判断中的作用
  13. PCAN Explorer之plot插件导出数据时间格式转换
  14. flutter 背景图片毛玻璃效果
  15. 利用python进行股票分析(五)通过tushare读取股票数据
  16. 元胞自动机——应用于森林火灾和传染病场景
  17. JavaSE-Lambada
  18. 实现MapX的移屏测距功能(转)
  19. C语言线程lock与unlock,lock()和unlock()是怎么实现【面试题详解】
  20. cocos creator 制作作砸金蛋

热门文章

  1. mysql数据库sql注入原理_SQL注入原理解析以及举例1
  2. 就业技术书文件表格_公路工程全套资料—开工施工检验等表格范本,及监理内业常用资料...
  3. 神经网络的全连接层_深度神经网络全连接层
  4. Angular安装教程
  5. Ubuntu16.04LTS修改开机动画
  6. iOS VIPER架构(三)
  7. Spring框架知识复习之二
  8. 【rman】list archivelog all与list backup of archivelog all
  9. win7安装python
  10. java8 lambda表达式实现自定义用户组件,Don't Repeat Yourself