运行结果:
root@ubuntu:/home/topeet/guyilian# javac Ext2.java
root@ubuntu:/home/topeet/guyilian# java Ext2
10
ustc
**子类继承父类的方法和属性都可以进行覆写,我们在子类覆写父类的printInfo方法。**
class Person {
private int age;
public void setAge(int age) {if (age < 0 || age > 200)age = 0;else {this.age = age;}
}public int getAge() {return age;
} public void printInfo() {System.out.println("age = "+age);
}
}
class Student extends Person{
private String school;
public void setSchool(String school) {this.school = school;
}public String getSchool() {return school;
} public Student(String school) {this.school = school;
}/* override */
public void printInfo() {System.out.println("school = "+school+"; age = "+getAge());
}
}
public class Ext3 {
public static void main (String args[]) {
Student stu = new Student(“ustc”);
stu.setAge(10);System.out.println(stu.getAge());System.out.println(stu.getSchool());stu.printInfo();
}
}
运行结果:
root@ubuntu:/home/topeet/guyilian# javac Ext3.java
root@ubuntu:/home/topeet/guyilian# java Ext3
10
ustc
school = ustc; age = 10
**实例化子类对象时,先调用父类的构造方法,再调用子类的构造方法,super()函数在子类中可以指定调用父类构造函数的类型。**
class Person {
private int age;
public void setAge(int age) {if (age < 0 || age > 200)age = 0;else {this.age = age;}
}public int getAge() {return age;
} public void printInfo() {System.out.println("age = "+age);
}public Person () {System.out.println("Person ()");}
public Person (int age) {System.out.println("Person (int age)");this.age = age;
}
}
class Student extends Person{
private String school;
public void setSchool(String school) {this.school = school;
}public String getSchool() {return school;
} public Student(String school) {/* will call the super() *///super();super(5);System.out.println("Student(String school)");this.school = school;
}/* override */
public void printInfo() {System.out.println("school = "+school+"; age = "+getAge());
}
}
public class Ext4 {
public static void main (String args[]) {
Student stu = new Student(“ustc”);
//stu.setAge(10);System.out.println(stu.getAge());System.out.println(stu.getSchool());stu.printInfo();
}
}
运行结果:
root@ubuntu:/home/topeet/guyilian# javac Ext4.java
root@ubuntu:/home/topeet/guyilian# java Ext4
Person (int age)
Student(String school)
5
ustc
school = ustc; age = 5
**抽象类规定子类必须实现的方法,起“模板”作用,缺点不能实例化对象,子类必须覆写全部抽象方法。**
abstract class Father {
private int money;
public int getMoney() {return money; }
public void setMoney(int money) {this.money = money; }public abstract void study();
}
class Son extends Father{
public void study() {System.out.println(“I am study”); }
}
public class Ext6 {
public static void main (String args[]) {
//Father f = new Father();
Son son = new Son();
son.study();
}
}
运行结果:
root@ubuntu:/home/topeet/guyilian# javac Ext6.java
root@ubuntu:/home/topeet/guyilian# java Ext6
I am study
**作用:跟抽象类相似,起“模板”作用;子类可以继承多个接口,突破“单继承”的限制。**
abstract class Father {
private int money;
public int getMoney() {return money; }
public void setMoney(int money) {this.money = money; }public abstract void study();
}
class Son extends Father{
public void study() {System.out.println(“I am study”); }
}
public class Ext6 {
public static void main (String args[]) {
//Father f = new Father();
Son son = new Son();
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数嵌入式工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年嵌入式&物联网开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上嵌入式&物联网开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以+V:Vip1104z获取!!! (备注:嵌入式)
最后
资料整理不易,觉得有帮助的朋友可以帮忙点赞分享支持一下小编~
你的支持,我的动力;祝各位前程似锦,offer不断,步步高升!!!
后续会持续更新**
如果你觉得这些内容对你有帮助,可以+V:Vip1104z获取!!! (备注:嵌入式)
最后
资料整理不易,觉得有帮助的朋友可以帮忙点赞分享支持一下小编~
你的支持,我的动力;祝各位前程似锦,offer不断,步步高升!!!
更多资料点击此处获qu!!