class Animal { void eat() {…"在吃东西"} void call() {…"(动物叫)"} }
class Dog extends Animal { @Override void call() {…"汪汪"} }
new Dog().eat(); // 动物在吃东西 ← 继承来的
new Dog().call(); // 汪汪 ← 重写了
println(对象) 时 Java 自动调它Student@6b67034;重写后:Student{name=张三, age=18}4 档权限:public 所有人 | 不写 = 同一个包(文件夹)里的类 | protected(先跳过)| private 只有自己 小练习不写图省事;正式代码要写清楚(demo1:方法 public、属性 private)
引号里的原样照抄,引号外的变量换成值,首尾粘起来
"Student{name=" + name + ", age=" + age + "}" → Student{name=张三, age=18}
花括号、等号、逗号都只是引号里的普通文字(真跑过 T19.java)
| 题 | 我答 | 结果 |
|---|---|---|
| Cat 什么都没写,c.call() | (动物叫) | ✅ 继承来的 |
name="李四", age=20:name + "的年龄是" + age |
李四的年龄是 20 | ✅(实际没有空格:李四的年龄是20) |