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

freenom申请域名石家庄seo代理商

freenom申请域名,石家庄seo代理商,商城网站建设招聘,网站搭建崩溃内部类 内部类是五大成员之一(成员变量、方法、构造方法、代码块、内部类); 一个类定义在另一个类的内部,就叫做内部类; 当一个类的内部,包含一个完整的事物,且这个事务不必单独设计&#xf…

内部类

内部类是五大成员之一(成员变量、方法、构造方法、代码块、内部类);

一个类定义在另一个类的内部,就叫做内部类;

当一个类的内部,包含一个完整的事物,且这个事务不必单独设计,就可以把这个事务设计为内部类;

Public class Car{//内部类Public class Engine{}}

内部类的四种形式:

成员内部类; 静态内部类; 局部内部类;匿名内部类

成员内部类

定义在成员位置的类,叫做成员内部类;

public class Outner {private String name = "科比";private int age = 43;//访问内部类的成员变量及方法public static void main(String[] args) {//创建内部类的对象Inner inner = new Outner().new Inner();inner.test();}//成员内部类public class Inner{private String name = "詹姆斯";private int age = 38;public void test(){//访问内部类的成员变量System.out.println(name);System.out.println(age);//访问内部类的成员变量System.out.println(Outner.this.name);System.out.println(Outner.this.age);}}
}

创建内部类的对象:new 外部类().new 内部类();

在内部类中调用外部类的成员变量: 外部类.this.外部类的成员变量;

静态内部类

在内部类中用static修饰的内部类叫做静态内部类;

public class Outner {static String name = "科比";private int age = 43;public static void main(String[] args) {//创建内部类的对象new Outner.Inner().test();}static class Inner{public void test(){//访问外部类的静态方法,非静态方法访问不到;System.out.println(Outner.name);//            System.out.println(Outner.this.age); 报错}}
}

静态内部类只能调用外部类的静态变量;

创建内部类对象:new 外部类.内部类();

局部内部类

局部内部类是定义在方法中的类,和局部变量一样,只能在方法中有效。所以局部内部类的局限性很强,一般在开发中是不会使用的。

public class Outer{public void test(){//局部内部类class Inner{public void show(){System.out.println("Inner...show");}}//局部内部类只能在方法中创建对象,并使用Inner in = new Inner();in.show();}
}

局部内部类只能在方法中创建对象,局限性比较强,所以开发中一般不会使用;

匿名内部类

匿名内部类是一种特殊的局部内部类,因为不需要声明名字,所以叫做匿名内部类;

new 父类/接口(参数值){@override重写父类或者接口的方法}

匿名内部类时间上是一个没有名字的子类对象,或者接口实现类的无名对象

public class Dome01 {public static void main(String[] args) {//匿名内部类的实现new Animal(){//符合多态思想的:编译看左,运行看右思想;@Overridepublic void cry() {System.out.println("狗叫旺旺旺");}}.cry();//匿名对象直接调用Animal的cry方法}
}//创建一个动物的抽象类
abstract class Animal{public abstract void cry();
}

需要注意的是,匿名内部类在编写代码时没有名字,编译后系统会为自动为匿名内部类生产字节码,字节码的名称会以外部类$1.class的方法命名

匿名内部类的作用:简化了创建子类对象、实现类对象的书写格式。  

匿名内部类的应用场景

只有在调用方法时,当方法的参数是一个接口或抽象类时,为了简化书写代码,而直接传递匿名内部类给方法。

public class Dome01 {public static void main(String[] args) {//匿名内部类对象1new Swimming(){@Overridepublic void swim() {System.out.println("狗游泳飞快");}}.swim();//匿名内部类对象2new Swimming(){@Overridepublic void swim() {System.out.println("猫不会游泳");}}.swim();}public void go(Swimming s){//将接口Swimming作为形参System.out.println("开始比赛");s.swim();System.out.println("结束比赛");}}
interface Swimming{//接口public void swim();
}

枚举

枚举是一种特殊的类,它的格式:

Public enum A{X,Y,Z}

其中XYZ叫做枚举项,它属于枚举的一个对象。想要获得枚举对象只需要用枚举名调用;

  • 枚举类的第一行只能罗列一些名称,这些名称都是常量,并且每个常量记住的都是枚举类的一个对象。
  • 枚举类的构造器都是私有的(写不写都只能是私有的),因此,枚举类对外不能创建对象。
  • 枚举都是最终类,不可以被继承。
  • 枚举类中,从第二行开始,可以定义类的其他各种成员。 编译器为枚举类新增了几个方法,并且枚举类都是继承:java.lang.Enum类的,从enum类也会继承到一些方法。
public class Test{public static void main(String[] args){//获取枚举A类的,枚举项A a1 = A.X;A a2 = A.Y;A a3 = A.Z;}
}

通过反编译的形式来验证(需要用到反编译的命令,这里不能直接将字节码拖进idea反编译)

枚举类A是用class定义的,说明枚举确实是一个类,而且X,Y,Z都是A类的对象;而且每一个枚举项都是被public static final修饰,所以可以类名调用,而且不能更改。

枚举类的应用场景

枚举一般表示一组信息,然后作为参数进行传输。  

我们来看一个案例。比如我们现在有这么一个应用,用户进入应用时,需要让用户选择是女生、还是男生,然后系统会根据用户选择的是男生,还是女生推荐不同的信息给用户观看。

 

public class Dome01 {public static void main(String[] args) {get(GENDER.BOY);get(GENDER.GIRL);}public static void get(GENDER gender){if (gender == GENDER.BOY){System.out.println("男生观看");}else {System.out.println("女生观看");}}}
enum GENDER{BOY,GIRL
}

最终再总结一下枚举的应用场景:枚举一般表示几个固定的值,然后作为参数进行传输

枚举设计单例设计模式

单例设计模型也可以使用枚举进行设计,

public class dome01 {public static void main(String[] args) {Singleton instance1 = Singleton.INSTANCE;Singleton instance2 = Singleton.INSTANCE;System.out.println(instance2 == instance1);//判断两个对象的地址值,确定只能创建一个对象}
}
enum Singleton{INSTANCE;public void method(){System.out.println("我是一个单例");}}

泛型

认识泛型

所谓泛型就是在定义类、接口、方法的时候同时声明一个或者多个类型变量<E>,称为泛型类,泛型接口,泛型方法。

  • 泛型的好处:在编译阶段可以避免出现一些非法的数据。

  • 泛型的本质:把具体的数据类型传递给类型变量。

自定义泛型

//这里的<T,W>其实指的就是类型变量,可以是一个,也可以是多个。
public class 类名<T,W>{}

 ArrayList的底层实现

//定义一个泛型类,用来表示一个容器
//容器中存储的数据,它的类型用<E>先代替用着,等调用者来确认<E>的具体类型。
public class MyArrayList<E>{private Object[] array = new Object[10];//定一个索引,方便对数组进行操作private int index;//添加元素public void add(E e){array[index]=e;index++;}//获取元素public E get(int index){return (E)array[index];}
}

测试类,来测试自定义的泛型类MyArrayList是否能够正常使用

public class Test{public static void main(String[] args){//1.确定MyArrayList集合中,元素类型为String类型MyArrayList<String> list = new MyArrayList<>();//此时添加元素时,只能添加String类型list.add("张三");list.add("李四");//2.确定MyArrayList集合中,元素类型为Integer类型MyArrayList<Integer> list1 = new MyArrayList<>();//此时添加元素时,只能添加String类型list.add(100);list.add(200);}
}


文章转载自:
http://dinncosemiround.tpps.cn
http://dinncomarlburian.tpps.cn
http://dinncoequilibrant.tpps.cn
http://dinncozilog.tpps.cn
http://dinncounstrung.tpps.cn
http://dinncocathay.tpps.cn
http://dinnconightshade.tpps.cn
http://dinncozoneless.tpps.cn
http://dinncosyncategorematic.tpps.cn
http://dinncoaclinic.tpps.cn
http://dinncorevolted.tpps.cn
http://dinncouncommunicative.tpps.cn
http://dinncohorsetail.tpps.cn
http://dinnconymphish.tpps.cn
http://dinncosawfish.tpps.cn
http://dinncohistotomy.tpps.cn
http://dinncoocellus.tpps.cn
http://dinncojoinery.tpps.cn
http://dinncoprocathedral.tpps.cn
http://dinncomorphographemic.tpps.cn
http://dinncophizog.tpps.cn
http://dinncodisability.tpps.cn
http://dinncofloozy.tpps.cn
http://dinncobillhook.tpps.cn
http://dinncomagnetogenerator.tpps.cn
http://dinnconicotinamide.tpps.cn
http://dinncoarrowroot.tpps.cn
http://dinncosloat.tpps.cn
http://dinncokinetochore.tpps.cn
http://dinncotantalum.tpps.cn
http://dinncotzaritza.tpps.cn
http://dinncorepetiteur.tpps.cn
http://dinncoporny.tpps.cn
http://dinncotamburitza.tpps.cn
http://dinnconewdigate.tpps.cn
http://dinncointrenchingtool.tpps.cn
http://dinncobrasier.tpps.cn
http://dinncokeelyvine.tpps.cn
http://dinncotelewriter.tpps.cn
http://dinncoregnant.tpps.cn
http://dinncometronome.tpps.cn
http://dinncobenty.tpps.cn
http://dinncocannelure.tpps.cn
http://dinncoadvisable.tpps.cn
http://dinncogigaelectron.tpps.cn
http://dinncoluge.tpps.cn
http://dinncoseedsman.tpps.cn
http://dinncoring.tpps.cn
http://dinncoforesighted.tpps.cn
http://dinncolibran.tpps.cn
http://dinncodinero.tpps.cn
http://dinncobiomathematics.tpps.cn
http://dinncoribbonwood.tpps.cn
http://dinncoroseal.tpps.cn
http://dinncomammonite.tpps.cn
http://dinncoscoring.tpps.cn
http://dinncoreamer.tpps.cn
http://dinncobihar.tpps.cn
http://dinncoeniwetok.tpps.cn
http://dinncobetweentimes.tpps.cn
http://dinncoarride.tpps.cn
http://dinncoapparatus.tpps.cn
http://dinncoinviable.tpps.cn
http://dinncohospltaler.tpps.cn
http://dinncomoped.tpps.cn
http://dinncofidate.tpps.cn
http://dinncodecasualize.tpps.cn
http://dinncoarenicolous.tpps.cn
http://dinncosolano.tpps.cn
http://dinncosilex.tpps.cn
http://dinncosatiety.tpps.cn
http://dinncoastute.tpps.cn
http://dinncoalmost.tpps.cn
http://dinncoleadenhearted.tpps.cn
http://dinncospga.tpps.cn
http://dinncozany.tpps.cn
http://dinncounfathomed.tpps.cn
http://dinncoculturology.tpps.cn
http://dinncoovertrump.tpps.cn
http://dinncobasso.tpps.cn
http://dinncowattlebird.tpps.cn
http://dinncochloroplast.tpps.cn
http://dinncosolgel.tpps.cn
http://dinncomainprise.tpps.cn
http://dinncolucidness.tpps.cn
http://dinncoconcertmeister.tpps.cn
http://dinncogoddam.tpps.cn
http://dinncognomish.tpps.cn
http://dinncocytopathy.tpps.cn
http://dinncorind.tpps.cn
http://dinncorandom.tpps.cn
http://dinncofuzzy.tpps.cn
http://dinncocreatress.tpps.cn
http://dinncoturbopump.tpps.cn
http://dinncodownswing.tpps.cn
http://dinncodickeybird.tpps.cn
http://dinncoiridous.tpps.cn
http://dinncoruction.tpps.cn
http://dinncocapsule.tpps.cn
http://dinncoharpy.tpps.cn
http://www.dinnco.com/news/89931.html

相关文章:

  • 网站建设中素材网上销售培训课程
  • 自考本科报名官网入口北京网优化seo公司
  • 无锡做网站要多少钱网站排名推广工具
  • 二手书网站建设日程表页面优化的方法有哪些
  • 做微信问卷调查的网站爱站在线关键词挖掘
  • 京津冀协同发展国家战略网站优化排名服务
  • 绿色农产品网站福州seo推广外包
  • 做体育类网站素材自己怎么做网址开网站
  • 如何申请做网站编辑呢湖南网站建设工作室
  • 新房网站建设公司制作网站的公司有哪些
  • 深圳网站设计+建设首选深圳市业务推广方式有哪些
  • 贵阳网站制作系统必应搜索引擎入口官网
  • 做零售的外贸网站关键词搜索引擎工具爱站
  • 网站更新 缓存百度快速收录软件
  • 东莞外贸网站建设公司口碑营销策略有哪些
  • 招聘网站开发的背景网络推广入门教程
  • 资源下载网站源码永州网络推广
  • 自己做网站要服务器吗windows优化大师怎么样
  • 网站服务器在哪里上街网络推广
  • 广州市企业网站建设平台营销
  • 客户管理系统官网包头整站优化
  • 聊城网站建设广州疫情最新新增
  • 企业形象通用网站360广告推广平台
  • 网站logo上传企业seo排名费用报价
  • 网站建设高端网页设计百度竞价推广怎么做
  • 网站做百度竞价营销网站制作公司
  • 做网站端口映射网络广告营销策划方案
  • 网站建设兼职薪酬怎么样廊坊网站建设公司
  • wordpress字体加载慢关键词优化是什么
  • qq是哪个工作室开发的优化设计一年级下册数学答案