123jgh

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

//快捷键ctrl+H!!!在Java中,所有的类都默认直接或者间接继承object类
//继承,父类(基类)
//Java中只有单继承,没有多继承(1->多)
public class person {
//public公共的
//protected优先级高的
//default默认的
//private私有的:私有的不能被继承

/*
private int money = 10_0000;


public void say(){
System.out.println("说了小秘密");
}

public int getMoney(){
return money;
}
public void setMoney(int money) {
this.money = money;
}
*/

public person(){
System.out.println("person有参调用了");
}

protected String name = "jiangjiangjiang";

public void print(){
System.out.println("PRESON");
}
}


//继承  学生也是人:派生类(子类)
//子类继承了父类,就会拥有父类的所有方法
public class Student extends person {

public Student(){

//隐藏代码:调用了父类的无参构造
super();//调用父类的构造器,必须要在子类构造器的第一行

System.out.println("Student无参调用了");
}

private String name = "jiangjiang";

public void print(){
System.out.println("STUDENT");
}

public void test1() {
print();
this.print();
super.print();
}

public void test(String name){
System.out.println(name);
System.out.println(this.name);
System.out.println(super.name);
}
}



public class Application {
public static void main(String[] args) {
/*
Student student = new Student();
student.say();

System.out.println(student.getMoney());
*/

Student student1 = new Student();

//student.test("江江");

//student.test1();
}
}



posted on   江江要努力  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
 
点击右上角即可分享
微信分享提示