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

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中为按钮添加图片

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543686.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

android Monkey 测试技巧

MonkeyTest 测试流程1、常用的命令参数说明:-sseed值,设置这个参数的主要作用是程序员可以重复执行这个命令,seed值相同则monkey测试序列也大致一样。-p 指定要测试的包,参数跟的是apk的package id--pct-touch 调整触摸…

十六进制数制到二进制,八进制和十进制数制的转换

Prerequisite: Number systems 先决条件: 数字系统 1)将十六进制数制转换为二进制数制 (1) Conversion of Hexadecimal Number System to Binary Number System) To convert hexadecimal numbers into binary numbers, we can use the relationship between hexade…

ldo regula_使用C中的Regula Falsi方法找到复多项式方程的根

ldo regulaRegula Falsi方法 (Regula Falsi method) About the method: 关于方法: We often hear many children and even many adults complaining about the difficulty level that they face while solving complex polynomial equations. It is also difficult…

解决一次由于SSL证书到期导致的网站不能访问的问题(Nginx,php,Apache)

1. 现象放假期间收到zabbix报警,提示主站访问不了,报502。2.排查思路及过程因为是过年休息,放假前又没有更新,基本可以排除是更新和配置导致的问题。ssh连上服务器发现服务器连接和资源都没问题。这是一套lnamp架构的网站&#xf…

python字典按键值排序_在Python中按键或值按升序和降序对字典排序

python字典按键值排序Problem Statement: Write a Python program to sort (ascending and descending) a dictionary by key or value. 问题陈述:编写一个Python程序,以按键或值对字典进行排序(升序和降序)。 Example: 例: Input: diction…

Try Redis : Redis 入门教程

开篇 Redis 是一种以键值对(key-value)存储数据的NoSQL数据库。 键值对存储数据的本质是以某个键存储某个值。之后你可以用这个键把存储的值取出来。可以用SET命令以键‘servername’存储值‘fido’: SET servername fido这样,数据…

在C ++中使用getter和setter函数创建具有X和Y轴的类Point

We have two declare a point class with two Axis X and Y and we have to create/design its getter and setter functions. 我们有两个声明带有两个Axis X和Y的点类,并且我们必须创建/设计其getter和setter函数。 As we know that a class has some data member…

go newscanner判断文件读取结束_Go单元测试-testing

在开发程序中,很重要一点就是测试,测试可以保证代码的质量,保证每个函数可以正常运行。但是如何保证写出来的程序是否正确。单元测试一般是用来测试我们的代码逻辑有没有问题,有没有按照我们期望的运行,以保证代码质量…

_.uniq_在Ruby中使用Array.compact和Array.uniq方法从Array中移除元素

_.uniqRuby Array.compact和Array.uniq方法 (Ruby Array.compact and Array.uniq Methods) In the last article, we have gone through two different methods of deleting elements from the Array. We have seen their implementation with the help of their syntaxes and …

清除缓存的实现

现有的清除缓存存在着一些问题,占坑查询,后续进行完善转载于:https://www.cnblogs.com/lazVy/p/5192244.html

divi模板下载_Java Math类静态double IEEEremainder(double divi,double divisor)的示例

divi模板下载数学类静态double IEEEremainder(double divi,double divisor) (Math Class static double IEEEremainder(double divi , double divisor)) This method is available in java.lang package. 此方法在java.lang包中可用。 This method is used to retur…

nextdate函数白盒测试问题 软件测试_软件测试基本常识

一、软件测试的分类:1.按照是否执行被测试软件来分:静态测试:是指不运行软件,测试包括代码检查、静态结构分析、代码质量度量等,主要对软件需求说明书、设计说明书、软件源代码进行检查与分析。 动态测试:…

java 大小写转换函数_不使用Java中的任何库函数将大写转换为小写

java 大小写转换函数Given a string and we have to convert it from uppercase to lowercase. 给定一个字符串,我们必须将其从大写转换为小写。 Examples: 例子: Input:IncludeHelp.comOutput:includehelp.comInput:[email protected]Output:[email p…

ideatomcat老是运行以前的项目_日“吞”150吨垃圾,禅城集中式餐厨垃圾处理项目启用...

12月9日,禅城区集中式餐厨垃圾处理项目正式投料试运行,该项目如今每天可处理150吨垃圾。这意味着禅城区将通过先进技术实现餐厨垃圾资源化、减量化、无害化处理。禅城区集中式餐厨垃圾处理项目位于佛山市南庄污水处理厂首期工程北侧,禅港路西…

【HDOJ】4363 Draw and paint

看题解解的。将着色方案映射为40*40*5*5*5*5*2个状态&#xff0c;40*40表示n*m,5*5*5*5表示上下左右相邻块的颜色&#xff0c;0表示未着色。2表示横切或者竖切。基本思路是记忆化搜索然后去重&#xff0c;关键点是可能未切前当前块已经着色了。 1 /* 4363 */2 #include <ios…

java怎么知道上传文件是否成功_文件包含漏洞之——tomcat CVE-2020-1938漏洞复现

这个漏洞是今年2月份出现的&#xff0c;他的影响范围也是非常广的。2月20日&#xff0c;国家信息安全漏洞共享平台&#xff08;CNVD&#xff09;发布了Apache Tomcat文件包含漏洞&#xff08;CNVD-2020-10487/CVE-2020-1938&#xff09;&#xff0c;这个漏洞是由于Tomcat AJP协…

css word-wrap_CSS中分词“ break-all”和“ break-word”的值之间的差异

css word-wrapDefinition: 定义&#xff1a; What is the most fundamental element that comes to mind when you are considering to develop a web page? Words! If that was your answer, then pat yourself because you are already aware of what we are going to disc…

Android Studio apk 打包流程

1.Build -> Generate Signed APK...&#xff0c;打开如下窗口 2.假设这里没有打过apk包&#xff0c;点击Create new&#xff0c;窗口如下 这里只要输入几个必要项 Key store path&#xff08;生产key文件的保存路径 &#xff09; Key store password&#xff08;key 存储密码…

update yum 到指定版本_CentOS系统升级至指定版本

摘要&#xff1a;CentOS系统下用yum updates命令默认只能升级到最新版本&#xff0c;CentOS仓库并不维护历史版本&#xff0c;所以只能使用 vault.centos.org 历史版本快照进行更新。本文以...CentOS系统下用yum updates命令默认只能升级到最新版本&#xff0c;CentOS仓库并不维…

Redis过期key清理机制

Redis的key过期时间探讨 说到Redis是一个典型的key-value非关系型数据库&#xff0c;存储的key基本都有过期时间&#xff0c;或者有默认的过期时间&#xff0c;或者不设置的话永久不失效&#xff08;内存空间足够大的情况下&#xff0c;生产环境一般放置系统的配置参数才这样&a…