无关紧要
This commit is contained in:
parent
58ad0dd15a
commit
a86d757053
@ -1,4 +1,14 @@
|
||||
package chapter4;
|
||||
|
||||
public class Examaple25 {
|
||||
public class Example25 {
|
||||
public static void main(String[] args) {
|
||||
int result = divide(4, 0);
|
||||
System.out.println("结果:" + result);
|
||||
|
||||
System.out.println("程序继续运行...");
|
||||
}
|
||||
|
||||
public static int divide(int x, int y) {
|
||||
return x / y;
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,36 @@
|
||||
package chapter4.example14;public class Example14 {
|
||||
package chapter4.example14;
|
||||
|
||||
abstract class Animal {
|
||||
abstract void shout();
|
||||
}
|
||||
|
||||
class Cat extends Animal {
|
||||
public void shout() {
|
||||
System.out.println("喵喵...");
|
||||
}
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
public void shout() {
|
||||
System.out.println("汪汪...");
|
||||
}
|
||||
}
|
||||
|
||||
class Example14 {
|
||||
public static void main(String[] args) {
|
||||
Animal cat = new Cat();
|
||||
Animal dog = new Dog();
|
||||
|
||||
cat.shout();
|
||||
dog.shout();
|
||||
}
|
||||
}
|
||||
|
||||
class Example15 {
|
||||
public static void main(String[] args) {
|
||||
Dog dog = new Dog();
|
||||
Animal an = dog;
|
||||
|
||||
an.shout();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package chapter4.object;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
class Student {
|
||||
private String name;
|
||||
private int age;
|
||||
@ -9,11 +11,17 @@ class Student {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Student {name=" + name + ", age=" + age + "}";
|
||||
}
|
||||
// public String toString() {
|
||||
// return "Student {name=" + name + ", age=" + age + "}";
|
||||
// }
|
||||
}
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Student s1 = new Student("张三", 23);
|
||||
|
||||
System.out.println(s1);
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user