public class Course {private String cNumber;private String cName;private int cUnit;public Course(String number, String name, int unit) {cNumber = number;cName = name;cUnit = unit;}public void printCourseInfo() {System.out.println("课程号:" + cNumber + "课程名:" + cName + "学分:" + cUnit);}}public class CourseTest {public static void main(String args[]){Course c;c = new Course("101", "JAVA程序设计", 3);c.printCourseInfo();}}
查看答案
public class Tom {private float weight;private static String name;public void setWeight(float weight) {this.weight = weight;}private void out() {System.out.println(name + "体重:" + weight + "斤");}public static void main(String[] args) {Tom.name = "kitty";Tom cat = new Tom();cat.setWeight(10);cat.out();}}
public class Test {public static void main(String[] args){int i=3;switch(i){default: System.out.print("not found");case 0: System.out.print("0");break;case 1:System.out.print("1");case 2:System.out.print("2");}}}
public class Father {String name, address, tel;int age;public Father(String name, int age) {this.name = name;this.age = age;}void out() {System.out.print("姓名:" + name);System.out.print("年龄:" + age);}void outOther() {System.out.print("家庭住址:" + address);System.out.print("电话:" + tel);}}class Son extends Father {String school;public Son(String name, int age) {super(name, age);}void out() {super.out();super.outOther();System.out.println("学校:" + school);}public static void main(String args[]) {Son son = new Son("Tom",22);son.address = "武清区";son.school = "天狮学院";son.tel = "123456";son.out();}}
public class MyClass {int a[] = { 1, 2, 3, 4, 5,6 };void out() {for (int j = 0; j < a.length; j++)System.out.print(a[j] + "");}public static void main(String[] args) {MyClass my = new MyClass();my.out();}}