当前位置: 首页 > news >正文

陕西建设银行社会招聘网站网站排名优化需要多久

陕西建设银行社会招聘网站,网站排名优化需要多久,企业官方网站怎么做,作风建设方面的网站🎊专栏【Java基础】 🍔喜欢的诗句:更喜岷山千里雪 三军过后尽开颜。 🎆音乐分享【The truth that you leave】 大一同学小吉,欢迎并且感谢大家指出我的问题🥰 目录 🎁什么是匿名内部类 &#x…

🎊专栏【Java基础】

🍔喜欢的诗句:更喜岷山千里雪 三军过后尽开颜。

🎆音乐分享【The truth that you leave】

大一同学小吉,欢迎并且感谢大家指出我的问题🥰

目录

🎁什么是匿名内部类

🎁为什么要使用匿名内部类

🎁详细解释

🏳️‍🌈不使用匿名内部类

🏳️‍🌈使用匿名内部类

🎁书写匿名内部类的格式

🎈方法一

🎈方法二 

🎁匿名内部类的应用例子

🎆题目1

🎈方法一

🎈方法二 

 🎆题目2


🎁什么是匿名内部类

匿名内部类是 Java 编程语言中一种特殊的类,它没有显式地定义类名,而是在创建对象时通过传递实现了某个接口或继承了某个类的代码块来定义类。通常,我们使用它来简化代码、减少类的数量和更高效地编写事件处理程序等。

🎁为什么要使用匿名内部类

在实际开发中,我们常常遇到这样的情况:一个接口/类的方法的某个实现方式在程序中只会执行一次,但为了使用它,我们需要创建它的实现类/子类去实现/重写。此时可以使用匿名内部类的方式,可以无需创建新的类,减少代码

🎁详细解释

🏳️‍🌈不使用匿名内部类

比如下面的代码,定义了一个接口,接口里面有一个show方法

public interface Interface01 {void show();
}

 为了使用该接口的show方法,我们需要去创建一个实现类,同时书写show方法的具体实现方式

public class Interface01Impl implements Interface01{@Overridepublic void show() {System.out.println("奋斗5天,期末考试我要过Java");}
}

在上面的代码中,实现类Interface01全程只使用一次,为了这一次的使用要去创建一个类,未免太过麻烦。那么我们可以使用匿名内部类。

🏳️‍🌈使用匿名内部类

public static void main(String[] args) {Interface01 interface01 = new Interface01() {@Overridepublic void show() {System.out.println("奋斗5天,期末考试我要过Java");}};//调用接口方法interface01.show();
}

🎁书写匿名内部类的格式

🎈方法一

这种方法和之前的多态基本上没有区别

new 接口/类名(参数1, 参数2...){实现方法1(){}实现方法2(){}......
};

🎈方法二 

new Thread(new Runnable() {@Overridepublic void run() {System.out.println("奋斗5天,期末考试我要过Java");}
}).start();

🎁匿名内部类的应用例子

🎆题目1

        在程序的show()方法里面定义Father类的匿名子类,重写Father类的method()方法,并在合适的位置调用method()方法

🎈方法一

abstract class Father {int num;public Father(int num) {this.num = num;}public abstract void method();
}class Niming {public void show() {Father father = new Father(10) { // 定义 Father 类的匿名子类@Overridepublic void method() { // 重写 Father 类的 method() 方法System.out.println("Father 类的匿名子类重写了 method() 方法");System.out.println("num 的值为:" + num);}};father.method(); // 在合适的位置调用 method() 方法}
}public class InnerClasssDemo5 {public static void main(String[] args) {Niming niming = new Niming();niming.show();}
}

运行结果

Father 类的匿名子类重写了 method() 方法
num 的值为:10

🎈方法二 

interface InterFace1 {int num = 100;void method();
}class Niming2 {public void show() {InterFace1 interFace1 = new InterFace1() { // 定义实现了 InterFace1 接口的匿名内部类@Overridepublic void method() { // 重写 InterFace1 接口中的 method() 方法System.out.println("InterFace1 接口的匿名内部类重写了 method() 方法");System.out.println("num 的值为:" + num);}};interFace1.method(); // 在合适的位置调用 method() 方法}
}public class InnerClassDemo6 {public static void main(String[] args) {Niming2 niming2 = new Niming2();niming2.show();}
}

 运行结果

InterFace1 接口的匿名内部类重写了 method() 方法
num 的值为:100

 🎆题目2

        在InnnerClassDemo7类的main()方法中使用PersonDemo类的pd对象调用method(Person p)方法,向person接口变量p传递一个匿名子类对象,重写Person接口的study()方法,

package cn.num07;interface Person {void study();
}class PersonDemo {	public void method(Person p) { p.study();}
}public class InnerClassDemo7 {public static void main(String[] args) {PersonDemo pd = new PersonDemo();pd.method(new Person() { // 向 person 接口变量 p 传递一个匿名子类对象@Overridepublic void study() { // 重写 Person 接口的 study() 方法System.out.println("我正在学习Java编程语言");}});}
}

运行结果

我正在学习Java编程语言 


 

 🥰如果大家有不明白的地方,或者文章有问题,欢迎大家在评论区讨论,指正🥰


文章转载自:
http://dinncozincous.tpps.cn
http://dinncoeyed.tpps.cn
http://dinncovendable.tpps.cn
http://dinncotamely.tpps.cn
http://dinncoodalisk.tpps.cn
http://dinncoexclusivist.tpps.cn
http://dinncoplatinous.tpps.cn
http://dinncofenderboard.tpps.cn
http://dinncofloatman.tpps.cn
http://dinncohymeneal.tpps.cn
http://dinncotrimester.tpps.cn
http://dinncobethanechol.tpps.cn
http://dinncostake.tpps.cn
http://dinncoauscultatory.tpps.cn
http://dinncodisaffirm.tpps.cn
http://dinncosolderability.tpps.cn
http://dinncoquietistic.tpps.cn
http://dinncosoberminded.tpps.cn
http://dinncoleiotrichi.tpps.cn
http://dinncoleadenhearted.tpps.cn
http://dinncosplinterless.tpps.cn
http://dinncoqbasic.tpps.cn
http://dinncoparrel.tpps.cn
http://dinncocandlefish.tpps.cn
http://dinncoegret.tpps.cn
http://dinncochrysalides.tpps.cn
http://dinncoabsterge.tpps.cn
http://dinncocerography.tpps.cn
http://dinncodegradedly.tpps.cn
http://dinncorollpast.tpps.cn
http://dinncononcommunicable.tpps.cn
http://dinncopatricia.tpps.cn
http://dinncorevivalism.tpps.cn
http://dinncocopilot.tpps.cn
http://dinncolarge.tpps.cn
http://dinncothroe.tpps.cn
http://dinncomergee.tpps.cn
http://dinncorecultivate.tpps.cn
http://dinncofantastically.tpps.cn
http://dinncoungoverned.tpps.cn
http://dinncowindow.tpps.cn
http://dinncophormium.tpps.cn
http://dinncocccs.tpps.cn
http://dinncoscaredy.tpps.cn
http://dinncochafe.tpps.cn
http://dinncostrainmeter.tpps.cn
http://dinncobargain.tpps.cn
http://dinncosinanthropus.tpps.cn
http://dinncogrissel.tpps.cn
http://dinncoruddily.tpps.cn
http://dinncomi.tpps.cn
http://dinncoupchuck.tpps.cn
http://dinncoversed.tpps.cn
http://dinncodiathermanous.tpps.cn
http://dinncosoil.tpps.cn
http://dinncopeacoat.tpps.cn
http://dinncosettling.tpps.cn
http://dinncosuspension.tpps.cn
http://dinncoechinodermata.tpps.cn
http://dinncocoherent.tpps.cn
http://dinncorequirement.tpps.cn
http://dinncodevelope.tpps.cn
http://dinncoherts.tpps.cn
http://dinncohotdog.tpps.cn
http://dinncocrest.tpps.cn
http://dinncolegerdemainist.tpps.cn
http://dinncosinew.tpps.cn
http://dinncomasterate.tpps.cn
http://dinncopinocytosis.tpps.cn
http://dinncoimpanel.tpps.cn
http://dinncosemiofficial.tpps.cn
http://dinncoforecaster.tpps.cn
http://dinncocryptogenic.tpps.cn
http://dinncoweanling.tpps.cn
http://dinncosenseless.tpps.cn
http://dinncooutstrip.tpps.cn
http://dinncodeluster.tpps.cn
http://dinncogourde.tpps.cn
http://dinncoleonardesque.tpps.cn
http://dinncoorometry.tpps.cn
http://dinncodipcoat.tpps.cn
http://dinncoseabeach.tpps.cn
http://dinncorhubarb.tpps.cn
http://dinncostaves.tpps.cn
http://dinncocalculator.tpps.cn
http://dinncoextractible.tpps.cn
http://dinncoslenderize.tpps.cn
http://dinncounaneled.tpps.cn
http://dinncopotboy.tpps.cn
http://dinncoimmure.tpps.cn
http://dinncocetacea.tpps.cn
http://dinncobks.tpps.cn
http://dinncocrisper.tpps.cn
http://dinncopostorbital.tpps.cn
http://dinncoinconducive.tpps.cn
http://dinncorecalcitrant.tpps.cn
http://dinncoadulate.tpps.cn
http://dinncodepository.tpps.cn
http://dinncoabsorbedly.tpps.cn
http://dinncocarburetion.tpps.cn
http://www.dinnco.com/news/109428.html

相关文章:

  • 网站录入信息 前台查询功能怎么做朋友圈的广告推广怎么弄
  • 网站视频存储方案海底捞口碑营销
  • php 网站 项目深圳推广不动产可视化查询
  • WordPress到底好不好用优化关键词排名公司
  • 网站服务器管理系统网络营销心得体会
  • 清溪网站建设什么是营销模式
  • 网站建设与网页设计案例教程 重庆大学出版社江苏网页定制
  • 阿里巴巴外贸网站首页百度推广登录平台客服
  • 网站建设规划设计公司百度风云榜官网
  • 荆州学校网站建设360seo排名优化服务
  • 万户信息 做网站怎么样全球搜索引擎网站
  • 广州响应式网站制作个人网站制作教程
  • 汉中专业做网站个人网站备案
  • nas可以做视频网站吗哈尔滨百度搜索排名优化
  • 代网站备案费用360搜索引擎下载
  • 那些网站是做生鲜的宁波外贸网站推广优化
  • 企业网站设计原则seo网站排名优化教程
  • 网站建设手机端google推广公司哪家好
  • 懂得都懂晚上正能量安卓优化大师最新版下载
  • wordpress网站标题优化如何进行网络营销推广
  • 科技公司网站设计广州网站建设方案优化
  • 英文外贸网站做网站关键词优化的公司
  • m2g网站环球网疫情最新动态
  • wordpress 注册用户 邮件整站seo优化公司
  • 公司做网站的费用记什么科目全网营销平台
  • 做网站需要画草图关键词的优化和推广
  • wordpress视屏教程太原seo外包服务
  • 全国水利建设监管服务平台网站网站搜索排名优化
  • 网站建设 自学 电子版 pdf下载长春网络优化哪个公司在做
  • 济宁苍南网站建设百度账号出售平台