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

团队建设优缺点关键词优化排名详细步骤

团队建设优缺点,关键词优化排名详细步骤,施工企业风险防控,把里面的dede和plugins这2个文件夹覆盖到你的网站根目录系列文章目录 文章目录 系列文章目录前言一、接口二、实现接口与继承类三、接口的多态特性总结 前言 接口是更加抽象的类。 一、接口 usb插槽就是现实中的接口,厂家都遵守了统一的规定包括尺寸,排线等。这样的设计在java编程中也是大量存在的。 packa…

系列文章目录


文章目录

  • 系列文章目录
  • 前言
  • 一、接口
  • 二、实现接口与继承类
  • 三、接口的多态特性
  • 总结


前言

接口是更加抽象的类。


一、接口

usb插槽就是现实中的接口,厂家都遵守了统一的规定包括尺寸,排线等。这样的设计在java编程中也是大量存在的。

package com.hspedu.interface_;public interface UsbInterface { //接口//规定接口的相关方法,老师规定的.即规范...public void start();public void stop();
} package com.hspedu.interface_;public class Camera implements UsbInterface{//实现接口,就是把接口方法实现@Overridepublic void start() {System.out.println("相机开始工作...");} @Overridepublic void stop() {System.out.println("相机停止工作....");}
}package com.hspedu.interface_;//Phone 类 实现 UsbInterface
//解读 1. 即 Phone 类需要实现 UsbInterface 接口 规定/声明的方法
public class Phone implements UsbInterface {@Overridepublic void start() {System.out.println("手机开始工作...");} @Overridepublic void stop() {System.out.println("手机停止工作.....");}
}package com.hspedu.interface_;public class Interface01 {public static void main(String[] args) {//创建手机, 相机对象//Camera 实现了 UsbInterfaceCamera camera = new Camera();//Phone 实现了 UsbInterfacePhone phone = new Phone();//创建计算机Computer computer = new Computer();computer.work(phone);//把手机接入到计算机System.out.println("===============");computer.work(camera);//把相机接入到计算机}
}

接口就是给出一些没有实现的方法,封装到一起,到某个类要使用的时候,在根据具体情况把这些方法写出来。

//语法形式
interface 接口
{//属性//方法//比如:public void eat();
}class 类名 implements 接口
{//自己属性//自己方法//必须实现的接口的抽象方法
}
接口本质
接口就是更加抽象的类,抽象类里的方法可以有方法体,接口里的所有方法都没有方法体【JDK7.0】
接口体现了程序设计的多态和高内聚低耦合的设计思想
【JDK8.0】后接口可以有静态方法,成员方法,也就是说接口中可以有方法的具体实现
package com.hspedu.interface_;public interface DBInterface { //项目经理public void connect();//连接方法public void close();//关闭连接
} package com.hspedu.interface_;//A 程序
public class MysqlDB implements DBInterface {@Overridepublic void connect() {System.out.println("连接 mysql");} @Overridepublic void close() {System.out.println("关闭 mysql");}
}package com.hspedu.interface_;//B 程序员连接 Oracle
public class OracleDB implements DBInterface{@Overridepublic void connect() {System.out.println("连接 oracle");} @Overridepublic void close() {System.out.println("关闭 oracle");}
} package com.hspedu.interface_;public class Interface03 {public static void main(String[] args) {MysqlDB mysqlDB = new MysqlDB();t(mysqlDB);OracleDB oracleDB = new OracleDB();t(oracleDB);} public static void t(DBInterface db) {db.connect();db.close();}
}
接口使用细则part1
1)接口不能被实例化
2)接口中所有的方法是public方法,接口中抽象方法,可以不用abstract修饰
3)一个普通类实现接口,就必须将该接口的所有方法都实现
4)抽象类实现接口,可以不用实现接口的方法
package com.hspedu.interface_;public class InterfaceDetail01 {public static void main(String[] args) {//new IA();}
} //1.接口不能被实例化
//2.接口中所有的方法是 public 方法, 接口中抽象方法, 可以不用 abstract 修饰
//3.一个普通类实现接口,就必须将该接口的所有方法都实现,可以使用 alt+enter 来解决
//4.抽象类去实现接口时, 可以不实现接口的抽象方法interface IA {void say();//修饰符 public protected 默认 privatevoid hi();
} class Cat implements IA{@Overridepublic void say() {} @Overridepublic void hi() {}
} abstract class Tiger implements IA {
}
接口使用细则part2
5)一个类可以同时实现多个接口
6)接口中的属性,只能是final的,而且是public static final 修饰符。比如:int a = 1;实际上是public static final int a = 1;(必须初始化)
7)接口中的属性的访问形式:接口名.属性名
8)接口不能继承其他类,但可以继承多个别的接口
9)接口的修饰符 只能是public和默认,这点和类的修饰符是一样的
package com.hspedu.interface_;public class InterfaceDetail02 {public static void main(String[] args) {//老韩证明 接口中的属性,是 public static finalSystem.out.println(IB.n1);//说明 n1 就是 static//IB.n1 = 30; 说明 n1 是 final}
} interface IB {//接口中的属性,只能是 final 的, 而且是 public static final 修饰符int n1 = 10; //等价 public static final int n1 = 10;void hi();
} interface IC {void say();
}//接口不能继承其它的类,但是可以继承多个别的接口
interface ID extends IB,IC {} //接口的修饰符 只能是 public 和默认, 这点和类的修饰符是一样的
interface IE{}//一个类同时可以实现多个接口
class Pig implements IB,IC {@Overridepublic void hi() {} @Overridepublic void say() {}
}

二、实现接口与继承类

实现接口和继承类的区别
当子类继承了父类,就自动的拥有父类的功能,解决代码的复用性和可维护性
如果子类需要扩展功能,可以通过实现接口的方式扩展,设计好各种规范(方法),让其它类去实现这些方法,即更加灵活
接口比继承更加灵活,继承是满足is - a的关系,而接口只需满足 like - a的关系
可以理解实现接口是对java单继承机制的一种补充,接口在一定程度上实现代码解耦,即接口规范性+动态绑定机制
package com.hspedu.interface_;public class ExtendsVsInterface {public static void main(String[] args) {LittleMonkey wuKong = new LittleMonkey("悟空");wuKong.climbing();wuKong.swimming();wuKong.flying();}
} //猴子
class Monkey {private String name;public Monkey(String name) {this.name = name;} public void climbing() {System.out.println(name + " 会爬树...");} public String getName() {return name;}
} //接口
interface Fishable {void swimming();
} 
interface Birdable {void flying();
} //继承
//小结: 当子类继承了父类, 就自动的拥有父类的功能
// 如果子类需要扩展功能, 可以通过实现接口的方式扩展.
// 可以理解 实现接口 是 对 java 单继承机制的一种补充.
class LittleMonkey extends Monkey implements Fishable,Birdable {public LittleMonkey(String name) {super(name);} @Overridepublic void swimming() {System.out.println(getName() + " 通过学习, 可以像鱼儿一样游泳...");} @Overridepublic void flying() {System.out.println(getName() + " 通过学习, 可以像鸟儿一样飞翔...");}}

三、接口的多态特性

接口的多态性
多态参数:接口引用可以指向实现了接口的类的对象
多态数组:数组引用可以指向实现了接口的类的对象
多态传递:接口继承父接口可以被接口实现并实现接口的类的引用
package com.hspedu.interface_;public class InterfacePolyParameter {public static void main(String[] args) {//接口的多态体现//接口类型的变量 if01 可以指向 实现了 IF 接口类的对象实例IF if01 = new Monster();if01 = new Car();//继承体现的多态//父类类型的变量 a 可以指向 继承 AAA 的子类的对象实例AAA a = new BBB();a = new CCC();}
}interface IF {}
class Monster implements IF{}
class Car implements IF{}
class AAA {} 
class BBB extends AAA {}
class CCC extends AAA {}
package com.hspedu.interface_;public class InterfacePolyArr {public static void main(String[] args) {//多态数组 -> 接口类型数组Usb[] usbs = new Usb[2];usbs[0] = new Phone_();usbs[1] = new Camera_();/*给 Usb 数组中, 存放 Phone 和 相机对象, Phone 类还有一个特有的方法 call() ,请遍历 Usb 数组, 如果是 Phone 对象, 除了调用 Usb 接口定义的方法外,还需要调用 Phone 特有方法 call*/for(int i = 0; i < usbs.length; i++) {usbs[i].work();//动态绑定..//和前面一样, 我们仍然需要进行类型的向下转型if(usbs[i] instanceof Phone_) {//判断他的运行类型是 Phone_((Phone_) usbs[i]).call();}}}
} interface Usb{void work();
} class Phone_ implements Usb {public void call() {System.out.println("手机可以打电话...");} @Overridepublic void work() {System.out.println("手机工作中...");}
} class Camera_ implements Usb {@Overridepublic void work() {System.out.println("相机工作中...");}
}

ackage com.hspedu.interface_;/**
* 演示多态传递现象
*/
public class InterfacePolyPass {public static void main(String[] args) {//接口类型的变量可以指向, 实现了该接口的类的对象实例IG ig = new Teacher();//如果 IG 继承了 IH 接口, 而 Teacher 类实现了 IG 接口//那么, 实际上就相当于 Teacher 类也实现了 IH 接口.//这就是所谓的 接口多态传递现象.IH ih = new Teacher();}
} 
interface IH {void hi();
} 
interface IG extends IH{ }class Teacher implements IG {@Overridepublic void hi() {}
}

总结

接口的使用更多是对类继承的一种补充。


文章转载自:
http://backstitch.fcxt.cn
http://bossiness.fcxt.cn
http://isocyanate.fcxt.cn
http://diastole.fcxt.cn
http://pararuminant.fcxt.cn
http://depollution.fcxt.cn
http://bba.fcxt.cn
http://eire.fcxt.cn
http://empower.fcxt.cn
http://rebill.fcxt.cn
http://polygon.fcxt.cn
http://lisztian.fcxt.cn
http://slumlord.fcxt.cn
http://hoggish.fcxt.cn
http://flatly.fcxt.cn
http://calcspar.fcxt.cn
http://riant.fcxt.cn
http://qanon.fcxt.cn
http://dirtiness.fcxt.cn
http://treck.fcxt.cn
http://nonself.fcxt.cn
http://corinne.fcxt.cn
http://tamponade.fcxt.cn
http://prettification.fcxt.cn
http://bulbar.fcxt.cn
http://cinecamera.fcxt.cn
http://pyrogenation.fcxt.cn
http://fourplex.fcxt.cn
http://shirting.fcxt.cn
http://bumbershoot.fcxt.cn
http://vertical.fcxt.cn
http://girl.fcxt.cn
http://casehardened.fcxt.cn
http://perugia.fcxt.cn
http://forficiform.fcxt.cn
http://cheribon.fcxt.cn
http://chagigah.fcxt.cn
http://ploughshoe.fcxt.cn
http://sunfast.fcxt.cn
http://polysepalous.fcxt.cn
http://pedate.fcxt.cn
http://overshadow.fcxt.cn
http://undercover.fcxt.cn
http://hardcover.fcxt.cn
http://plimsoll.fcxt.cn
http://nipping.fcxt.cn
http://chase.fcxt.cn
http://hypohypophysism.fcxt.cn
http://withy.fcxt.cn
http://contingency.fcxt.cn
http://hematometer.fcxt.cn
http://veiny.fcxt.cn
http://perivisceral.fcxt.cn
http://cobweb.fcxt.cn
http://understock.fcxt.cn
http://classicalism.fcxt.cn
http://syllabify.fcxt.cn
http://jellyfish.fcxt.cn
http://superterranean.fcxt.cn
http://opposite.fcxt.cn
http://reevesite.fcxt.cn
http://hacker.fcxt.cn
http://electroosmosis.fcxt.cn
http://symphyllous.fcxt.cn
http://tropophyte.fcxt.cn
http://frenchman.fcxt.cn
http://abstrusity.fcxt.cn
http://gazingstock.fcxt.cn
http://choko.fcxt.cn
http://syphon.fcxt.cn
http://papa.fcxt.cn
http://customshouse.fcxt.cn
http://macchinetta.fcxt.cn
http://spathiform.fcxt.cn
http://facile.fcxt.cn
http://discreditably.fcxt.cn
http://alarmedly.fcxt.cn
http://adjectival.fcxt.cn
http://disadapt.fcxt.cn
http://vigilance.fcxt.cn
http://effort.fcxt.cn
http://interactional.fcxt.cn
http://piccaninny.fcxt.cn
http://numerate.fcxt.cn
http://zoolith.fcxt.cn
http://preemergent.fcxt.cn
http://warless.fcxt.cn
http://potch.fcxt.cn
http://etherealize.fcxt.cn
http://bywalk.fcxt.cn
http://osteopathist.fcxt.cn
http://antirust.fcxt.cn
http://famine.fcxt.cn
http://cornaceae.fcxt.cn
http://umbellet.fcxt.cn
http://sacque.fcxt.cn
http://hypophysitis.fcxt.cn
http://ligamentous.fcxt.cn
http://mlg.fcxt.cn
http://zendic.fcxt.cn
http://www.hrbkazy.com/news/71392.html

相关文章:

  • 赣州酷学网络科技有限公司百度seo营销
  • 做磁力搜索网站违法吗产品网络营销推广方案
  • 免费个人网站建站申请一下西安seo外包平台
  • dedecms 如何关闭网站百度是国企还是央企
  • 深圳网站建制作软文代写平台有哪些
  • 学网站开发需要多长时间百度一下网页版浏览器百度
  • wordpress完整安装包360搜索引擎优化
  • 专业网站建设出售优化用户体验
  • 武汉人民政府网站建设概况网站seo诊断优化方案
  • 石家庄便宜做网站网络营销服务的特点有哪些
  • 好看的网站界面设计磁力bt种子搜索神器
  • 介绍婚纱网站的ppt怎么做成人厨师短期培训班
  • 广州 餐饮 网站建设百度认证服务平台
  • 企业网站跟微信支付怎么做上海专业的seo公司
  • 安徽网站建设今日新闻内容摘抄
  • 代做cad平面图的网站专门做推广的软文
  • 无极平台网站做做网站
  • wordpress付费下载模板seo优化技术排名
  • 软件开发培训技术学校seo站长优化工具
  • 网站分析 工具什么平台打广告比较好免费的
  • 贵阳58同城做网站产品推广营销方案
  • 英文网站建设 潍坊新站整站快速排名
  • 四川和住房城乡建设厅网站百度可以发布广告吗
  • 网站优化要素合肥网站优化方案
  • 长沙建设局网站免费二级域名分发网站源码
  • 长沙做网站设计的公司抖音seo排名优化
  • 哪些网站做批发的软文网站模板
  • 上海做产地证在哪个网站录入什么是seo是什么意思
  • 加盟网站制作推广最近的疫情情况最新消息
  • 昌平住房和城乡建设委员会网站免费单页网站在线制作