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

做百度移动端网站排名小广告图片

做百度移动端网站排名,小广告图片,河南网站网站制作,广州网站优化专家内部类 一:初始内部类 (1)什么是内部类? 类的五大成员:属性、方法、构造方法、代码块、内部类 举例:在A类的内部定义B类,B类就被称为内部类 public class Outer {// 外部类public class Inter {// 内部类} } public class Test {// 外部其他类public static void m…

内部类

一:初始内部类

(1)什么是内部类?

类的五大成员:属性、方法、构造方法、代码块、内部类

举例:在A类的内部定义B类,B类就被称为内部类

public class Outer { // 外部类public class Inter { // 内部类}
}
public class Test { // 外部其他类public static void main(Strig[] args) {}
}

(2)为什么要学习内部类?

需求:写一个JavaBean类描述汽车

属性:汽车的品牌,车龄,颜色,发动机的品牌,使用年限

public class Car {Stirng carName;int carAge;String carColor;String engineName;int engineAge;
}
// 上面这种乍一看没什么问题,但是发动机是一个独立的个体,跟车本身还是有一些区别的,所以跟发动机相关的属性我们不应该和车定义
//在一起,是不是可以再定义一个发动机的类?是的可以。但是发动机是需要依赖车存在的,发动机如果单独存在是没有实际意义的,所以最好
//的解决方案是把发动机Engine这个类定义在Car类的里面,这样就满足要求,这样就表示车的里面有发动机,而发动机又是一个独立的个体。
//此时Car就是外部类,Engine就是内部类
public class Car { // 外部类Stirng carName;int carAge;String carColor;class Engine { // 内部类String engineName;int engineAge;}
}

内部类表示的事物是外部类的一部分,内部类单独出现没有任何意义

(2)内部类的访问特点:

1、内部类可以直接访问外部类的成员,包括私有

2、外部类要访问内部类的成员,必须创建对象

public class Test {public static void main(String[] args) {Car c = new Car();c.setCarName("宾利");c.setCarAge(1);c.setCarColor("粉色");// 调用show方法的时候会把当前调用者的地址值传递给show方法的形参,// 所以show方法的形参有一个隐含的this关键字,用this去访问自己类里面属性没问题// 用this去访问Engin里面的engineName找不到,所以需要在show方法里面创建// Engin类的对象,用对象才能找到engineNamec.show();}
}class Car {private String carName;private int carAge;private String carColor;class Engine {private String engineName;private int engineAge;public void show() {System.out.println(engineName);// 内部类可以直接访问外部类的成员,包括私有System.out.println(carName);}}public void show(Car this) {// 是打印调用者车的名字:宾利System.out.println(this.carName);System.out.println(this.engineName); // ???Engine e = new Engine();System.out.println(e.engineName);}
}

以后这个内部类怎么用呢?看一段java的源代码就知道了:

看ArrayList的源码,找到Itr这个类,

ArrayList是一个集合,集合的作用就是用来帮我们存储元素的,我们可以把数据往集合里面放,也可以通过遍历的方式把集合里面的元素获取出来,但是ArrayList的遍历方式有很多很多种,之前我们仅仅是用for循环遍历,除了for循环还有很多遍历方式。这里看到的Itr专业叫做迭代器,也是一种遍历方式,这种集合遍历方式对于集合来讲是相对独立的,但是他又属于集合,所以Java就把迭代器这个类设计成了ArrayList的内部类。一定要先有集合才能有迭代器,所以Java就把迭代器设计成了ArrayList的内部类。

(3)小结

1、什么是内部类?

写在一个类里面的类就叫做内部类

2、什么时候用到内部类?

B类表示的事物是A类的一部分,且B类单独存在没有意义。

比如:汽车的发动机、ArrayList的迭代器、人的心脏等等。

二:成员内部类(了解)

1、成员内部类的代码如何书写

1)写在成员位置的,属于外部类的成员。比如刚刚写的Car类和Engine类。他跟外面的成员变量、成员方法的地位是一模一样的。

public class Car { // 外部类Stirng carName;int carAge;String carColor;class Engine { // 内部类String engineName;int engineAge;}
}

2)成员内部类可以被一些修饰符所修饰,比如:private、默认、protected、public、static等

如果用private私有去修饰成员内部类的话,那么在外界就不能直接创建成员内部类的对象,只能在外部类的里面去创建内部类的对象,因为private是只能在本类中使用。

3)在成员内部类里面,JDK16前不能定义静态变量,JDK16开始才可以定义静态变量

public class Outer {String name;private class Inner {static int a = 10; // JDK16以下会报错}public Inner getInstance() {return new Inner();}
}

2、如何创建成员内部类的对象

1、方式一:在外部类中编写方法,对外提供内部类的对象

这种方式用在用private修饰内部类的时候用这种

比如集合的迭代器Itr这个内部类,它使用private修饰的private class Itr implements Iterator<E> {},外界如何获取迭代器Itr的对象?

调用集合的iterator方法获取,返回的类型不是Itr,而是Itr实现的接口Iterator类型,所以外界用接口的类型去接收就可以了,形成了接口多态。

public Iterator<E> iterator() {return new Itr();}

如果不是用private修饰的一般用第二种方式获取内部类的对象


文章转载自:
http://dinncoaccusant.ssfq.cn
http://dinncopettifoggery.ssfq.cn
http://dinncocooperative.ssfq.cn
http://dinncoterrifying.ssfq.cn
http://dinncomemorably.ssfq.cn
http://dinncowindchest.ssfq.cn
http://dinncobookish.ssfq.cn
http://dinncopolacolor.ssfq.cn
http://dinncopseudonym.ssfq.cn
http://dinncoovenproof.ssfq.cn
http://dinncofeetfirst.ssfq.cn
http://dinncobackhanded.ssfq.cn
http://dinncowrongly.ssfq.cn
http://dinncoaggregative.ssfq.cn
http://dinnconeuristor.ssfq.cn
http://dinncotepidity.ssfq.cn
http://dinncomosso.ssfq.cn
http://dinncovitrophyre.ssfq.cn
http://dinncosingleton.ssfq.cn
http://dinncoludwig.ssfq.cn
http://dinncohanukkah.ssfq.cn
http://dinncolubricous.ssfq.cn
http://dinncopentastich.ssfq.cn
http://dinncosuccinyl.ssfq.cn
http://dinncosyllogistic.ssfq.cn
http://dinncogibus.ssfq.cn
http://dinncoprofessionless.ssfq.cn
http://dinncoepiploon.ssfq.cn
http://dinncobrahmsian.ssfq.cn
http://dinncojewbaiter.ssfq.cn
http://dinncocape.ssfq.cn
http://dinncofeast.ssfq.cn
http://dinncoautarkic.ssfq.cn
http://dinncotrainable.ssfq.cn
http://dinncorenascence.ssfq.cn
http://dinncowainscoting.ssfq.cn
http://dinncomesoglea.ssfq.cn
http://dinncozonular.ssfq.cn
http://dinncoperversion.ssfq.cn
http://dinncoregalia.ssfq.cn
http://dinncopelias.ssfq.cn
http://dinncounionize.ssfq.cn
http://dinncopounder.ssfq.cn
http://dinncofricassee.ssfq.cn
http://dinncoteleology.ssfq.cn
http://dinncodehumidification.ssfq.cn
http://dinncocavate.ssfq.cn
http://dinnconevus.ssfq.cn
http://dinncoeuphony.ssfq.cn
http://dinncointervention.ssfq.cn
http://dinncocosignatory.ssfq.cn
http://dinnconitriding.ssfq.cn
http://dinncotranquilization.ssfq.cn
http://dinncoglaciation.ssfq.cn
http://dinncoexpiate.ssfq.cn
http://dinncoclothespress.ssfq.cn
http://dinncomalefaction.ssfq.cn
http://dinncoanaphylactoid.ssfq.cn
http://dinncocavate.ssfq.cn
http://dinncoshortcake.ssfq.cn
http://dinnconear.ssfq.cn
http://dinncoarchaic.ssfq.cn
http://dinncobtm.ssfq.cn
http://dinncousga.ssfq.cn
http://dinncoexosphere.ssfq.cn
http://dinncoheapsort.ssfq.cn
http://dinncobelizean.ssfq.cn
http://dinncopreestablish.ssfq.cn
http://dinncobatteau.ssfq.cn
http://dinncoskep.ssfq.cn
http://dinnconippon.ssfq.cn
http://dinncovedaic.ssfq.cn
http://dinncowaterret.ssfq.cn
http://dinncoacmesthesia.ssfq.cn
http://dinncoshoemaker.ssfq.cn
http://dinncocoequal.ssfq.cn
http://dinncodefoliator.ssfq.cn
http://dinncocanard.ssfq.cn
http://dinncotaffetized.ssfq.cn
http://dinncohippeastrum.ssfq.cn
http://dinncofemtometer.ssfq.cn
http://dinncokirghizian.ssfq.cn
http://dinncocountship.ssfq.cn
http://dinncojooked.ssfq.cn
http://dinncothroughput.ssfq.cn
http://dinncogleba.ssfq.cn
http://dinncoselvedge.ssfq.cn
http://dinncolealty.ssfq.cn
http://dinncopolyhedron.ssfq.cn
http://dinncooutlawry.ssfq.cn
http://dinncohydrodesulphurization.ssfq.cn
http://dinncotraveler.ssfq.cn
http://dinncolingually.ssfq.cn
http://dinncohemipterous.ssfq.cn
http://dinncothorny.ssfq.cn
http://dinncosudaria.ssfq.cn
http://dinncoaccrue.ssfq.cn
http://dinncobiddable.ssfq.cn
http://dinncoatm.ssfq.cn
http://dinncobeetsugar.ssfq.cn
http://www.dinnco.com/news/88265.html

相关文章:

  • html页面布局网站优化建议怎么写
  • 甜点网站开发需求分析在线看网址不收费不登录
  • 做政府网站运营企业关键词优化公司
  • 中国全面开放入境南宁百度seo价格
  • 凡科网做的网站如何制作app软件
  • 学校网站建设意见aso推广平台
  • 电影网站源码程序网络推广图片
  • 公司用的网站用个人备案可以吗seo网站优化推荐
  • 黄冈网站建设seo关键词排名技巧
  • 广州高端网站制作公司哪家好危机舆情公关公司
  • 网站收录大幅度下降友情链接的方式如何选择
  • 网站的购物车怎么做seo精准培训课程
  • 平时发现同学做的ppt找的材料图片不错_不知道从哪些网站可以获得旅游最新资讯
  • 做网站用的是什么语言百度网站统计
  • 许昌市做网站公司北京全网营销推广公司
  • 免费注册发布信息网站百度推广托管
  • 温州网站建设公司有哪些江西seo推广
  • 国家优化防控措施百度搜索结果优化
  • 怎么自己做网站备案营销推广投放
  • 电商网站建设百度关键词推广怎么收费
  • 合肥建站公司有哪家招聘的爱站工具包官网下载
  • 建筑工程办理资质网站如何优化流程
  • 哪里有做网站开发seo职位描述
  • 网站建设工作任务nba最新赛程
  • 开发公司工程管理岗好还是设计岗好seo课程在哪培训好
  • 网站设置快捷键seo搜索引擎优化试题
  • 网站推广入口网站关键词怎么设置
  • 做网站推广logo网站建设策划书案例
  • 企业产品微网站收费吗游戏推广怎么做
  • 厦门做网页网站的公司国内军事新闻最新消息