Cal
Cal
package day_06.Cal;
public class Cal {
protected int num1;
protected int num2;
public Cal() {
super();
}
public Cal(int num1, int num2) {
super();
this.num1 = num1;
this.num2 = num2;
}
public int getResult() {
System.out.println("Cal.getResult()");
return 0;
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
}
Add
package day_06.Cal;
public class Add extends Cal{
public Add() {
super();
}
public Add(int num1, int num2) {
super(num1, num2);
}
@Override
public int getResult() {
return num1 + num2;
}
}
CalMain
package day_06.Cal;
public class CalAddMainTest {
public static void main(String[] args) {
Add add=new Add(2,3);
System.out.println(add.getResult());
}
}
AbstractCal
Cal
package day_06.AbstractCal;
public abstract class Cal {
protected int num1;
protected int num2;
public Cal() {
}
public Cal(int num1, int num2) {
this.num1 = num1;
this.num2 = num2;
}
public abstract int getResult();
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
}
Add
package day_06.AbstractCal;
public class Add extends Cal{
public Add() {
}
public Add(int num1, int num2) {
super(num1, num2);
}
@Override
public int getResult() {
return num1+num2;
}
}
AbstractCalAddMain
package day_06.AbstractCal;
public class CalAddMainTest {
public static void main(String[] args) {
Add add=new Add(2,3);
System.out.println(add.getResult());
}
}
PerStud
Person
package day_06.PerStu;
public class Person {
protected int id;
protected String name;
protected int age;
public Person() {
}
public Person(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public void show(){
System.out.println(name+"年龄是"+age+",id:"+id);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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;
}
}
Student
package day_06.PerStu;
public class Student extends Person{
private String className;
public Student() {
}
public Student(int id, String name, int age, String className) {
super(id, name, age);
this.className=className;
}
@Override
public void show(){
super.show();
System.out.println("在"+className+"班.");
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}
PerStudMain
package day_06.PerStu;
public class PerStuMainTest {
public static void main(String[] args) {
Student student=new Student(1,"zhang",20,"UI4");
student.show();
}
}