package com.ctgu.java.exer; import java.util.Scanner; public class TestPerson { public static void main(String[] args){ Person p1 = new Person(); p1.info(); p1.name = "lovejia"; p1.age = 21; p1.sex = true; p1.setName("lovejia"); p1.info(); Person p2 = p1 ; System.out.println("p1:"+ p1); System.out.println("p2:"+ p2); p2.info(); p2 = new Person(); p2.info(); System.out.println("p2:"+ p2); Scanner s = new Scanner(System.in); int i = s.nextInt(); } } class Person{ //属性: String name; int age; boolean sex; //方法: public void eat(){ System.out.println("人吃饭"); } public void sleep(){ System.out.println("人睡觉"); } public String getName(){ return name; } public void setName(String n ){ name = n ; } public void info(){ //eat(); //sleep(); System.out.println("name:"+name+" age:"+age+" sex:"+sex);{ } } }
时间: 2024-10-10 06:59:50