zoukankan      html  css  js  c++  java
  • super 和this的用法

    class Person {

    public static void prt(String s) {
    System.out.println(s); // 打印出来结果
    }

    Person() {
    prt("父类无参构造方法.");
    }

    Person(String name) {
    prt("父类有参构造方法" + name);

    }
    }
    public class superyongfa extends Person{
    superyongfa() // 子类无参构造函数或构造方法
    {
    super(); // 调用父类构造函数(1)
    prt("子类无参构造方法");// (4)
    }

    superyongfa(String name) {
    super(name);// 调用父类具有相同形参的构造函数(2)
    prt("子类一个元素构造方法" + name);
    }

    superyongfa(String name, int age) {
    this(name);// 调用当前具有相同形参的构造函数(3)
    prt("子类两个元素构造方法:" + age);
    }

    public static void main(String[] args)
    {
    superyongfa cn = new superyongfa();
    cn = new superyongfa("kevin"); // 无论怎么样,先调用类的无参构造函数或方法,然后再调用相同参数的那个构造函数与方法

    cn = new superyongfa("kevin", 22);// 但是有两个 superyongfa的话,就第一次 调用无参构造方法,第二次调用相同参数的
    }

    }

  • 相关阅读:
    scgi_params
    ngin 模块及模板
    nginx常用模块
    HTML
    nginx部署网页小游戏
    nginx的server标签还有日志管理
    关于使用yum安装的nginx的主从配置文件的碎碎念
    判断所ping主机的操作系统
    CentOS 7修改主机名
    CentOS7 设置系统时间
  • 原文地址:https://www.cnblogs.com/bluewelkin/p/3402187.html
Copyright © 2011-2022 走看看