第七周学习总结

(二)接口的细节

 

(三)练习

 

 1 public class Person {
 2 private String name;
 3 private int age;
 4 publicPerson()
 5 public Person(String name,int age) {
 6 this.name = name;
 7 this.age = age;
 8 }
 9 public String gethane{
10 return name;
11 }
12 public void setName(String name) 
13 {this.name = name;}
14 public int getAge(){
15 return age;
16 }
17 public void setAge(int age){
18 this.age = age;
19 }
20 }
 1 public abstract class extends Person{
 2 
 3  public Coach(){
 4 }
 5 public Coach(String name, int age) {
 6 super(name, age);
 7 }
 8 public abstract void teach();
 9 }
10  
11 public abstract class extends Person{
12 public Sporter(){
13 }
14 public Sporter(String name, int age) {
15 super(name, age);
16 }
17 public abstract void study();
18 }
19 }
public interface English {
  public abstract void speakEnglish();
}

public class PingPangSporter extends Sporter implements English{
public PingPangsporter() {
}
publicPingPangSporter(String name, int age){
super(name, age);
}
@Override
public void speakEnglish() {
System.out.println("乒乓球运动员在说亮语");
}
@Override
public void study() {
System.out.println(乒乓球运动员在学习如何打乒乓球”);
}
}

public class BasketballSporter extends  Sporter{
publicBasketbaliSporter(){
}
public BasketballSporter(String name, int age) {
super(name, age);
}
@Ovarnide
public void study(){
system.out.orintln("篮球运动员在学习如何打篮球”);
}
}
 1 public class Pingpangcoach extends Coach implements English{
 2 public PingPangCoach(){
 3 }
 4 public PingpangCoach(String name, int age) {
 5 super(name, age);
 6 }
 7  
 8 public void teach() {
 9 System.out.print1n(“乒乓球教练正在教如何打乒乓球");
10 }
11 @Override
12 public void speakEnglish
13 System.out.println(乒乓球教练在学习说英语");
14 }
15 }
16 
17 public class Basketballcoach extends Coach{
18  public BasketballCoach( ){
19 }
20 public BasketballCoach(String name, int age) {
21 super(name, age);
22 }
23 @Override
24 public void teach(){
25 System.out.println("篮球教练正在教如何打篮球”);
26 }
27 }
28 public classTest
29 public static vold main(Stringt  args){
30 }
31 PingPangSporter pps = new PingPangSporter( name:"刘诗雯”,age:23);
32 System.out.println( pps.getAge());
33 pps.study();
34 pps.speakEnglish();
35 }
36 }

 

三、内部类

(一)初识

 

 1 public class Car {
 2 String carName;
 3 int carAge;
 4 String carColor;
 5 
 6 class Engine{
 7 String engineName;
 8 int engineAge;
 9 
10 }
11 }

 

(二)成员内部类

 

 1 public class Outer {
 2  private int a = 10;
 3  
 4  class Inner {
 5    private int a = 20;
 6     
 7     public void show() {
 8           
 9        int a = 30;
10        System.out.println( Outer.this.a); // 10
11        System.out.println( this.a); // 20
12        System.out.println( a); // 30
13 }
14 }
15 }

 

(三)静态,局部内部类

 

 1 public class Outer {
 2 int a=10;
 3 static int b=20;
 4 
 5    static class Inner {
 6     public void show() {
 7           
 8       Outer o = new Outer();
 9       System.out.println( O.a); 
10       System.out.println( b); 
11 }
12 }

 

(四)匿名内部类

 

 1 public class Test{ 
 2 public static void main(String[]  args) {
 3 
 4 Dog d = new Dog();
 5 method(d);
 6 
 7 method(
 8     new Animal() {
 9       @Override
10       public  void eat(){
11          System.out.println("狗吃骨头");
12  }
13  }
14 );
15 }
16 public static  void  method(Animal a){
17 a.eat();
18 }
19 }

 

 

下周学习:项目,界面

posted @ 2022-08-13 17:21  旺旺大菠萝  阅读(26)  评论(0编辑  收藏  举报