「Java学习打卡」26、面向对象程序练习

import java.util.Scanner;

public class Test {
     
    public static void main(String[] args) {
     
        // 实例化子类对象s,调用talk()方法打印信息
        Student s = new Student();
        System.out.println("请输入学生信息(姓名 年龄 学校):");
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        int b = scan.nextInt();
        String c = scan.next();
        System.out.println(s.talk(a, b, c));
    }
}

class Person {
     
    public Person(String n, int a) {
     
        this.name(n);
        this.age(a);
    }

    String name(String n) {
     
        return "我是:" + n + ",";
    }

    String age(int a) {
     
        return "今年:" + a + "岁,";
    }

    String talk(String n, int a) {
     
        String s = name(n);
        String d = age(a);
        return s + d;
    }
}

class Student extends Person {
     
    public Student() {
     
        super("null", 0);
    }

    void school(String sc) {
     
        System.out.println("学校:" + sc);
    }

    String talk(String n, int a, String sc) {
     
        super.talk(n, a);
        return super.talk(n, a) + "我在" + sc + "上学";

    }
}
package FirstProgram;

interface Message {
     
    public String getContent();
}

class SMessage implements Message{
     
    public String getContent(){
     
        return "My Message";
    }

}
public class Test {
     
    public static void main(String[] args) {
     
        Message ms = new SMessage();
        System.out.print(ms.getContent());
    }
}

你可能感兴趣的:(「Java学习打卡」26、面向对象程序练习)