第十周上机练习
Posted sehnsucht
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十周上机练习相关的知识,希望对你有一定的参考价值。
package work; public class Student { String name; double grade; public Student(){ } public Student(String name,double score){ this.name=name; this.grade=grade; } public void setName(String name){ this.name=name; } public void setGrade(double grade){ this.grade=grade; } public String getName(){ return name; } public double getGrade(){ return grade; } public void show(){ System.out.println("学生的姓名是:"+getName()+"成绩为:"+getGrade()); } } package work; public class Test { public static void main(String[] args) { Student st1=new Student(); st1.setName("zhangsan"); st1.setGrade(99); st1.show(); Student st2=new Student("lisi",100); st2.show(); }
package work; public class Person { public Person(){ } public void say(){ System.out.println("无参的构造方法被调用了..."); } } package work; public class Test { public static void main(String[] args) { Person p1=new Person(); p1.say(); } }
package work; public class Car { private String name; private char color; public Car(String name,char color){ this.name=name; this.color=color; } public String getName(){ return name; } public char getColor(){ return color; } public void setName(String name){ this.name=name; } public void setColoe(char color){ this.color=color; } public void run(){ System.out.println("一辆"+getColor()+"的"+getName()+"正在跑"); } }
package kkk; public class Demo { public static void main(String[] args) { Demo d1=new Demo(); int x=d1.get(1,2); System.out.println("和是:"+x); } public int get(int a,int b){ return a+b; } }
以上是关于第十周上机练习的主要内容,如果未能解决你的问题,请参考以下文章