zoukankan      html  css  js  c++  java
  • 实例化函数的具体步骤

    1、找父类的无参构造函数

    1.1、初始化成员变量

    1.2、实现构造函数中的方法体

    2、回到元类,并依次实现1.1和1.2

    3、注:this()、super(),位于构造函数第一位,语义是调用相应的构造函数

    this、super可任意在方法体中的位置调用,语义是调用相应方法和属性

    package com.jacob.javase.extend;
    
    public class Parent {
        int age;
        String username="xieji";
    
        public void getUsername(){
             System.out.println("parent username");
        }
    
        public Parent() {
            System.out.println("Parent wucan constructor");
        }
        public Parent(int i) {
    //      this();
            System.out.println("Parent youcan constructor");
        }
    
    }
    
    package com.jacob.javase.extend;
    
    public class Child extends Parent{
        String username="jacob";
    
        public void getUsername(){
             System.out.println("child username");
        }
    
        public Child() {
            super(1);
            System.out.println("child wucan constructor");
            System.out.println(super.username);
            super.getUsername();
        }
    
        public Child(int i) {
            System.out.println("child ycan constructor");
        } 
    }
    
    package com.jacob.javase.extend;
    
    public class Test {
     public static void main(String[] args) {
           new Child().getUsername();
           System.out.println(new Child().username);
    }
    }
    
  • 相关阅读:
    CF 429C
    GDOI2015滚粗记
    JLOI2015 城池攻占
    GDKOI2014 石油储备计划
    HNOI2012 射箭
    移动端复制到剪贴板
    再谈mobile web retina 下 1px 边框解决方案
    css去除chrome下select元素默认border-radius
    整理低版本ie兼容问题的解决方案
    移动端按钮交互变色实
  • 原文地址:https://www.cnblogs.com/xieji233/p/6155620.html
Copyright © 2011-2022 走看看