• JAVA 复写


    子类对introduce进行复写

    public class Person {
    
        String name;
        int age;
    
        Person(String name, int age) {
            this.name = name;
            this.age = age;
            System.out.println("Person 二参构造");
        }
    
        void introduce() {
            System.out.println("我的名字是" + name + ", 我的年龄是" + age);
        }
    }
    public class Student extends Person {
    
        String address;
    
        public Student(String name, int age, String address) {
            super(name, age);
            this.address = address;
        }
    
        void introduce() {
            System.out.println("我的名字是" + name + ", 我的年龄是" + age + ", 我的地址是" + address);
        }
    
    }
    public class Test {
    
        public Test() {
            // TODO Auto-generated constructor stub
        }
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Student student = new Student("furong", 12, "BeiJing");
            student.introduce();
        }
    
    }

    运行结果

    Person 二参构造
    我的名字是furong, 我的年龄是12, 我的地址是BeiJing

    子类改进

    public class Student extends Person {
    
        String address;
    
        public Student(String name, int age, String address) {
            super(name, age);
            this.address = address;
        }
    
        void introduce() {
            super.introduce();
            System.out.println("我的地址是" + address);
        }
    
    }
  • 相关阅读:
    hack games
    Metasploit 使用简介
    Back Track5学习笔记
    Metasploit没有db_autopwn命令的解决办法
    BT5 set_config各个选项的配置
    c# 截屏
    c#图像计算知识
    游戏代码
    Google Protocol Buffers (一个客户端与服务器协议生成工具)
    WinPcap抓取数据包
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/13595584.html
Copyright © 2020-2023  润新知