zoukankan      html  css  js  c++  java
  • java

    多态

    1.多态体现:方法重载、方法覆盖、多态参数。
    2.有继承关系时:运行期类型(子类)和编译期类型(父类),父类引用指向子类对象。
    3.多态参数:方法的形式参数类型是父类类型,传递的实际参数可以是任意子类的对象。
    4.多态环境下对象造型(向上造型,自动类型提升只能使用父类中的方法/向下造型,强制转换需要使用子类中的新方法时有此操作)
    5.instanceof操作符用于判断对象的具体类型

    泛型的概念和作用:

    1.泛型的本质是参数化类型

    2.在编译时检查类型的安全,消除强制类型转换。

    泛型类:声明类名后使用<E>,E可以为任何字母

    public class Animal<E> {

    private E name;

    public  Animal(){

    }

    }

    集合框架:

    三大接口(Collection 所有集合类的根接口; Map 映射接口,存放键值对; Iterator 遍历集合的迭代接口)

    list接口继承Collection接口,list集合中的元素都是有索引的

    List存在三个实现类(ArrayList 数组列表,数据采用数组方式存储;LinkedList 链表 ;Vector)

    set接口中的元素是不重复的,但是是无序的是没有索引的。

    set接口有两个实现类(HashSet 底层是哈希码值,基于HashMap实现的; TreeSet 元素不重复,并且元素实现了排序。)

    多线程编程:

    进程和线程(前者是正在执行的程序;后者是程序中的一个执行流;一个线程只能属于一个进程,而一个进程可以有多个线程,但至少有一个主线程)

    继承Thread类的方式 ;

    import java.lang.Thread;

    public class Mythread extends Thread{
    public static int ticket1 = 20;
    public void run(){
    System.out.println("开始卖票:"+Thread.currentThread().getName()+"窗口在售票;还剩"+ticket1--+"张票");
    }
    public static void main(String[] args) {
    // 创建多个线程
    Mythread th1 = new Mythread();
    Mythread th2 = new Mythread();
    Mythread th3 = new Mythread();
    Mythread th4 = new Mythread();
    Mythread th5 = new Mythread();
    //开始线程操作
    th1.start();
    th2.start();
    th3.start();
    th4.start();
    th5.start();
    }
    }

    实现Runnable接口的方式;

    import java.lang.Thread;

    class Myrunnable implements Runnable{
    public static int ticket=10;
    public void run(){
    System.out.println("开始卖票:"+Thread.currentThread().getName()+"窗口在售票;还剩"+ticket--+"张票");
    }
    public static void main(String[] args) {
    //创建一个对象
    Myrunnable a = new Myrunnable();
    Myrunnable b = new Myrunnable();
    Myrunnable c = new Myrunnable();
    Myrunnable d = new Myrunnable();
    Myrunnable e = new Myrunnable();
    Myrunnable f = new Myrunnable();
    //创建一个线程作为外壳将对象包括
    Thread th1 = new Thread(a,"线程1");
    Thread th2 = new Thread(b,"线程2");
    Thread th3 = new Thread(c,"线程3");
    Thread th4 = new Thread(d,"线程4");
    Thread th5 = new Thread(e,"线程5");
    Thread th6 = new Thread(f,"线程6");
    th1.start();
    th2.start();
    th3.start();
    th4.start();
    th5.start();
    th6.start();
    }
    }

  • 相关阅读:
    springboot+jsp 遇到的坑
    异步复位同步释放
    DDR工作原理(转载)
    FPGA基础 之逻辑单元
    二进制转BCD
    bcd转二进制
    FPGA学习笔记之IIC—EEPROM写和读
    FPGA学习笔记之mif文件生成方法总结
    FPGA_实验小项目:四位运算小计算器
    小小计算器之消零显示模块数码管消零
  • 原文地址:https://www.cnblogs.com/baichaofeng123/p/7157374.html
Copyright © 2011-2022 走看看