怎么每学到一个知识点就乱呢,,,我真担心自己的前途了.总是提示这个,代码应该没问题啊,定义为public了
- package com.baidu;
- public class Person {
- private String name;
- private int age;
- public Person() {}
- public Person(String name,int age) {
- this.name = name;
- this.age = age;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public int getAge() {
- return age;
- }
- }
复制代码
- package com.heima;
- import com.baidu.Person;
- public class Demo2_Package {
- public static void main(String[] args) {
- Person p = new Person("张三",18);
- System.out.println("名字" + p.getName() + "年龄" + p.getAge());
- }
- }
复制代码 |
|