Java作业七(2017-10-30),java作业2017-10-30

Java作业十二(2017-11-13),java作业2017-11-13

/*继承与抽象类*/
package com.baidu.www;
  abstract class Person {
    private String name;
    private int age;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public Person() {
        super();
    }
    @Override
    public String toString() {
        return "Person [name=" + name + ", age=" + age + "]";
    }
    public abstract String speak();
}


  class ZiXia extends Person{
    private float score;

    public ZiXia(String name, int age, float score) {
        super(name, age);
        this.setScore(score);
    }
    @Override
    public String speak() {
        return "紫霞信息:"+super.getName()+" "+super.getAge()+"岁 "+this.score+"人气";
    }
    public float getScore() {
        return score;
    }
    public void setScore(float score) {
        this.score = score;
    }
}


  class ZhiZunBao extends Person {
    private float salary;

    public ZhiZunBao(String name, int age, float salary) {
        super(name, age);
        this.setSalary(salary);
    }
    @Override 
    public String speak() {
        return "至尊宝信息:"+super.getName()+" "+super.getAge()+"岁 "+this.salary+"人气";
    }
    public float getSalary() {
        return salary;
    }
    public void setSalary(float salary) {
        this.salary = salary;
    }
}

public class GM {

    public static void main(String[] args) {
        Person ZiXia=new ZiXia("仙子",19,10);
        Person ZhiZunBao=new ZhiZunBao("人",18, 10);
        print(ZiXia.speak());
        print(ZhiZunBao.speak());
    }
    private static void print(String speak) {
        System.out.println(speak);
    }
}

  图片 1

/*继承与抽象类*/package com.baidu.www; abstract class Person { private
String name; private int age; public String get…

Java作业 十一(2017-11-13),java作业2017-11-13

/*关键字*/
package com.baidu.www;
 abstract class A {
    private String name;
    public A(String name) {
        this.name=name;
    }
    public String getName() {
        return this.name;
    }
    public abstract void fun();
}

class B extends A {
    public B(String name) {
        super(name);
    }
    public void fun() {
        System.out.println(super.getName());
    }

}

public class GM {

    public static void main(String[] args) {
        B b =new B("爱你一万年");
        b.fun();
    }
}

  

  图片 2

十一(2017-11-13),java作业2017-11-13
/*关键字*/package com.baidu.www; abstract class A { private String
name; public A(String name) { this.name=name; } publi…

Java作业七(2017-10-30),java作业2017-10-30

 1 /*造人*/
 2 public class Tman {
 3     public int id;
 4     public String name;
 5     public int age;
 6     public String city;
 7     public String introduce() {
 8       return  + id +  ":   name:  " + name + ", age:" + age + ", add:" + city ;
 9     }
10 }

 1 public class man {
 2 
 3     public static void main(String[] args) {
 4         // TODO Auto-generated method stub
 5         Tman p1=new Tman();
 6         Tman p2=new Tman();
 7         Tman p3=new Tman();
 8         Tman p4=new Tman();
 9                  p1.id=250;   p1.name="至尊宝";   p1.age=25;   p1.city="花果山";
10                  p2.id=250;   p2.name="紫霞";    p2.age=19;   p2.city="阿拉灯神丁";
11                  p3.id=250;   p3.name="青霞";    p3.age=19;   p3.city="阿拉灯神丁";
12                  p4.id=250;   p4.name="唐僧";    p4.age=43;   p4.city="盘丝洞";
13                  System.out.println(p1.introduce());
14                  System.out.println(p2.introduce());
15                  System.out.println(p3.introduce());
16                  System.out.println(p4.introduce());
17     }
18 
19 }

图片 3

1
/* 造人 */ 2 public class Tman { 3 public int id; 4 public String
name; 5 public int age; 6 public String city; 7 public St…

发表评论

电子邮件地址不会被公开。 必填项已用*标注