package cn.ALAN_CF.studyf003;
public class Main {
public static void main(String[] args) {
Aclass obj = new Aclass();
obj.foobar(15);
obj.foobar("Alan");
}
}
class Aclass{
public void foobar(int x) {
System.out.println("foobar (int x) : " + x);
}
public void foobar(String s){
System.out.println("foobar (String s) :" + s);
}
}
package cn.ALAN_CF.studyf004;
public class Main {
public static void main(String[] args) {
Person stu0 = new Person();
stu0.foobar();
Student stu1 = new Student();
stu1.foobar();
Person p = new Student();
p.foobar();
}
}
class Person{
public void foobar(){
System.out.println("Person: foobar");
}
}
class Student extends Person{
@Override
public void foobar(){
System.out.println("Student: foobar");
}
}
package cn.ALAN_CF.studyf005;
public class Student {
protected double regularGrade;
protected double finalExamGrade;
public Student(double regularGrade,double finalExamGrade){
this.regularGrade = regularGrade;
this.finalExamGrade=finalExamGrade;
}
public double totalMarks(){
return this.finalExamGrade;
}
public final void foobar(){
}
@Override
public String toString() {
return "Regular: " + this.regularGrade + " FinalExam: " +
this.finalExamGrade + " Total: " + this.totalMarks();
}
}
final class Person{
}
package cn.ALAN_CF.studyf005;
public class StudentOfAi extends Student{
public StudentOfAi(double regularGrade,double finalExamGrade){
super(regularGrade,finalExamGrade);
}
@Override
public double totalMarks(){
return 0.3 * this.regularGrade + 0.7 * this.finalExamGrade;
}
}
package cn.ALAN_CF.studyf005;
public class StudentOfEd extends Student{
public StudentOfEd(double regularGrade,double finalExamGrade){
super(regularGrade,finalExamGrade);
}
@Override
public double totalMarks(){
return 0.5 * this.regularGrade + 0.5 * this.finalExamGrade;
}
public double originMarks(){
return super.totalMarks();
}
}
package cn.ALAN_CF.studyf005;
public class Main {
public static void main(String[] args) {
Student[] students = new Student[]{
new StudentOfAi(80,60),
new StudentOfEd(60,80)
};
for(Student s: students) {
System.out.println(s);
}
}
}