Created
March 20, 2022 15:31
-
-
Save acmu/b46fdc15cb48098e03c29d8b48bac737 to your computer and use it in GitHub Desktop.
Java 继承示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Penguin { | |
private String name; | |
private int id; | |
public Penguin(String myName, int myid) { | |
name = myName; | |
id = myid; | |
} | |
public void eat(){ | |
System.out.println(name+"正在吃"); | |
} | |
public void sleep(){ | |
System.out.println(name+"正在睡"); | |
} | |
public void introduction() { | |
System.out.println("大家好!我是" + id + "号" + name + "."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Penguin { | |
private String name; | |
private int id; | |
public Penguin(String myName, int myid) { | |
name = myName; | |
id = myid; | |
} | |
public void eat(){ | |
System.out.println(name+"正在吃"); | |
} | |
public void sleep(){ | |
System.out.println(name+"正在睡"); | |
} | |
public void introduction() { | |
System.out.println("大家好!我是" + id + "号" + name + "."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment