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

个人网站 模版 后台管理系统外包公司值得去吗

个人网站 模版 后台管理系统,外包公司值得去吗,网架公司招聘打板施工队伍,html5做网站导航多态允许不同类的对象对同一消息做出不同的响应。在 Java 中,多态主要通过继承和接口实现。场景一:方法参数多态// 定义一个动物抽象类 abstract class Animal {public abstract void makeSound(); }// 定义猫类,继承自动物类 class Cat exte…

多态允许不同类的对象对同一消息做出不同的响应。在 Java 中,多态主要通过继承和接口实现。

场景一:方法参数多态

// 定义一个动物抽象类
abstract class Animal {public abstract void makeSound();
}// 定义猫类,继承自动物类
class Cat extends Animal {@Overridepublic void makeSound() {System.out.println("喵喵喵");}
}// 定义狗类,继承自动物类
class Dog extends Animal {@Overridepublic void makeSound() {System.out.println("汪汪汪");}
}// 定义一个动物操作类
class AnimalOperator {public void operate(Animal animal) {animal.makeSound();}
}public class PolymorphismExample {public static void main(String[] args) {AnimalOperator operator = new AnimalOperator();Cat cat = new Cat();Dog dog = new Dog();operator.operate(cat); // 传入猫对象operator.operate(dog); // 传入狗对象}
}

场景二:返回值多态

// 定义一个形状抽象类
abstract class Shape {public abstract double area();
}// 定义圆形类,继承自形状类
class Circle extends Shape {private double radius;public Circle(double radius) {this.radius = radius;}@Overridepublic double area() {return Math.PI * radius * radius;}
}// 定义矩形类,继承自形状类
class Rectangle extends Shape {private double width;private double height;public Rectangle(double width, double height) {this.width = width;this.height = height;}@Overridepublic double area() {return width * height;}
}// 定义一个形状工厂类
class ShapeFactory {public Shape createShape(int type) {if (type == 1) {return new Circle(5);} else {return new Rectangle(4, 6);}}
}public class ReturnPolymorphismExample {public static void main(String[] args) {ShapeFactory factory = new ShapeFactory();Shape shape1 = factory.createShape(1);Shape shape2 = factory.createShape(2);System.out.println("Shape 1 area: " + shape1.area());System.out.println("Shape 2 area: " + shape2.area());}
}

向上转型和向下转型示例

// 定义一个父类
class Parent {public void print() {System.out.println("This is Parent class");}
}// 定义一个子类
class Child extends Parent {@Overridepublic void print() {System.out.println("This is Child class");}public void childMethod() {System.out.println("This is a child-specific method");}
}public class TypeCastingExample {public static void main(String[] args) {// 向上转型Parent parent = new Child(); // 子类对象赋值给父类引用parent.print(); // 调用子类重写的方法// 向下转型if (parent instanceof Child) {Child child = (Child) parent; // 父类引用转换为子类引用child.print();child.childMethod(); // 调用子类特有的方法}}
}

instanceof 关键字使用示例

instanceof 关键字用于检查一个对象是否是某个类或接口的实例。

// 定义一个接口
interface Flyable {void fly();
}// 定义一个鸟类,实现 Flyable 接口
class Bird implements Flyable {@Overridepublic void fly() {System.out.println("Bird is flying");}
}// 定义一个飞机类,实现 Flyable 接口
class Plane implements Flyable {@Overridepublic void fly() {System.out.println("Plane is flying");}
}public class InstanceOfExample {public static void main(String[] args) {Flyable bird = new Bird();Flyable plane = new Plane();System.out.println(bird instanceof Bird); // 输出 trueSystem.out.println(bird instanceof Flyable); // 输出 trueSystem.out.println(plane instanceof Bird); // 输出 false}
}

http://www.dtcms.com/wzjs/482096.html

相关文章:

  • 台州网站建设搜狗seo优化
  • 360建筑网质量怎么样seo优化排名百度教程
  • app推广工作室沈阳百度推广排名优化
  • 深圳如何搭建建网站想在百度做推广怎么做
  • 做通信毕业设计的网站公司注册流程
  • 无锡阿里巴巴做网站福州360手机端seo
  • 电商网站变化现在阳性最新情况
  • 湘潭网站建设公司郑州优化网站关键词
  • 专业b2c电商网站开发线上购买链接
  • 在PC上安装WordPress武汉建站优化厂家
  • cnzz统计代码如何添加到网站上去关键词seo排名优化
  • 网站前端是做啥的哪个平台可以买卖链接
  • 最权威的网站推广公司怎样创建网站
  • seo网站诊断文档案例百度口碑官网
  • 太原响应式网站建设凡科网怎么建网站
  • 苹果CMS如何做视频网站厦门seo网站管理
  • 购物网站的后台站长工具之家
  • 贵州省兴义市专做网站公司品牌营销策划ppt
  • 济南网站建设sdqswl2022百度seo优化工具
  • oa厂家排名优化神马排名软件
  • 怎么建立网站 个人游戏广告联盟平台
  • 滕州哪里有做网站的百度竞价推广公司
  • 做挂网站吗国际网站平台有哪些
  • 哪家公司建设网站今日新闻快报
  • 想在网上做外卖 上什么网站好千锋教育培训机构可靠吗
  • 网站评论做外链seo需要会什么
  • 做信息类网站有哪些杭州网站建设书生商友
  • 吐血整理:2013最新外链网站大全_做seo再也不愁发外链了!通过百度指数不能判断出
  • 惠州做网站优化怎么在百度上投放广告
  • 沈阳设计网站公司哪家好百度网址安全检测