zoukankan      html  css  js  c++  java
  • JAVA

    面向对象的多态实现
    package
    duotaixing; public class next { public static void main(String[] args) { // TODO Auto-generated method stub next a=new next(); a.put(new zoo()); a.put(new dog()); a.put(new cat()); } public void put(zoo a){///可以从子类到父类的识别 a.eat(); a.sleep(); if(a instanceof dog) {///如果long转化int一般 dog b=(dog)a; b.good(); } if(a instanceof cat) { cat b=(cat)a; b.good(); } } } class zoo{ String name; int age; public void eat() { System.out.println("动物进食"); } public void sleep() { System.out.println("动物睡觉"); } } class dog extends zoo{///继承父类的属性 public void eat() { System.out.println("狗进食"); } public void sleep() { System.out.println("狗睡觉"); } public void good() { System.out.println("狗会看家"); } } class cat extends zoo{ public void eat() { System.out.println("猫进食"); } public void sleep() { System.out.println("猫睡觉"); } public void good() { System.out.println("猫会看家"); } }

    动物进食

    动物睡觉

    狗进食
    狗睡觉
    狗会看家
    猫进食
    猫睡觉
    猫会看家

     
    包装类的使用
    package
    nie; import org.junit.Test; public class leixing { @Test public void test1() { int a1=10; String str1=a1+""; Integer a2=a1; String str2=String.valueOf(a2);///基本类型----》String类。。调用String类的重载valueOf String str3=String.valueOf(true); System.out.println(a2); System.out.println(str1); System.out.println(str2); System.out.println(str3); int a3= Integer.parseInt(str2);///同上 相反 System.out.println(a3); boolean b=Boolean.parseBoolean(str3); System.out.println(b); } }

    10
    10
    10
    true
    10
    true

     
  • 相关阅读:
    用graphviz,pygraphviz快速自动绘图
    python 实现的huffman 编码压缩,解码解压缩
    python 字符串的显示
    PKU acm 1651 multiplication puzzle
    SQL Server中的数据类型详解
    (转) treeview 的设计思路
    将英文的week 转换为中文的 简单的方法
    常用的文件对应的MIME类型:
    客户端传参问题
    绑定数据与截取的另外的一中写法
  • 原文地址:https://www.cnblogs.com/a719525932/p/9381909.html
Copyright © 2011-2022 走看看