牛客刷题记录第三天

package object;
/**
* 1.子类构造器必须调用父类构造器
* 2.静态方法要想使用非静态属性和方法,必须要创建对象,用对象.属性,对象.方法(),
* 不能直接属性,方法()
*/
class Person {
String name = "No name";
public Person(String nm) {
name = nm;
}
}
class Employee extends Person {
String empID = "0000";
public Employee(String id) {
super("zs");
empID = id;
}
}
public class TestEmp {
int a = 1;
void test() {
System.out.println("test()");
}
static int b = 2;
static void test1() {
System.out.println("test2()");
}
public static void main(String args[]) {
Employee e = new Employee("123");
System.out.println(e.empID);
// 这两句会报错吗?
// System.out.println(a);
// test();
//必须创建对象才能使用非静态属性和方法
TestEmp testEmp = new TestEmp();
System.out.println(testEmp.a);
testEmp.test();
//静态属性和方法可以直接使用,无需创建对象
System.out.println(b);
test1();
}
}
posted @   yx1024  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
点击右上角即可分享
微信分享提示