- package cn.itcast.bean;
- public class Person {
- private static String name;
- private int age;
- public Person() {
- System.out.println("name=" + name + ",age=" + age);// 打印默认值
- }
- public Person(String name, int age) {
- super();
- this.name = name;
- this.age = age;
- }
- public static String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- @Override
- public String toString() {
- return "Person [name=" + name + ", age=" + age + "]";
- }
- }
- package cn.itacst.demo;
- import org.junit.Test;
- import cn.itcast.bean.Person;
- import cn.itcast.bean.Transportation;
- public class Demo {
- @Test
- public void Demo() {
- Person p = new Person("张三",23);
- System.out.println(p);
-
- }
- }
复制代码
这算是没有调用toString方法但是却执行了吗
没有调用方法但是方法却执行了 |
|