标签:
第一种方法;对象初始化。
package com.hanqi; import java.lang.*; public class student { int xuehao; String name; int age; student(int xuehao,String name,int age) { this.xuehao=xuehao; this.name=name; this.age=age; } void output() { System.out.println("学号:"+xuehao+" "+"姓名:"+name+" "+"年龄:"+age); } public static void main(String[] args) { student s1=new student(44,"小明",21); s1.output(); } }
第二中方法,在主类的main方法中创建多个Student类的对象,使用这些对象来测
package com.hanqi; public class textclass { public static void main(String[] args) { student s1 = new student(1,"小明",21); s1.output(); student s2 = new student(2,"小红",22); s2.output(); student s3 = new student(3,"小文",23); s3.output(); student s4 = new student(4,"小芳",24); s4.output(); } }
标签:
原文地址:http://www.cnblogs.com/zhailiming/p/5501898.html