标签:练习 package get bsp zhang system 构造方法 string int
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; } }
标签:练习 package get bsp zhang system 构造方法 string int
原文地址:https://www.cnblogs.com/sehnsucht/p/12843038.html