- class Person
- {
- private String name;
- private int age;
- Person(String name,int age)
- {
- this.name=name;
- this.age=age;
- }
- public void sayHello()
- {
- System.out.println("我叫"+name+","+"今年"+age+"岁了。");
- }
- }
- class Chinese extends Person
- {
- Chinese(String name, int age)
- {
- super(name, age);
- }
- public static void main(String[] args)
- {
- new Person("abc",100).sayHello();
- }
- }
复制代码
首先得有个main方法,没有入口JVM怎么运行..
然后你要调用方法..
多看几遍视频 |