1。People.java
public class People {
//性别(sex)及出生日期(date);方法成员有:获取人的性别和出生日期及构造方法。要求构造方法可以设置性别和出生日期的初始值。
private int sex
private Date birth
public People (int sex, Date birth) {
this.sex = sex
this.birth = birth
}
public int getSex() {
return this.sex
}
public Date getBirth() {
return this.birth
}
}
2。Student.java
public class Student extends People{
private int sex
private Date birth
private String name
private int stuno
private double grate
private String studentNative
public Student(int sex, Date birth, String name, int stuno, double grate, String studentNative) {
super(sex, birth)
this.name = name
this.stuno = stuno
this.grate = grate
this.studentNative = studentNative
}
public Date getBirth() {
return birth
}
public double getGrate() {
return grate
}
public String getName() {
return name
}
public int getSex() {
return sex
}
public String getStudentNative() {
return studentNative
}
public int getStuno() {
return stuno
}
}
3。测试类自己编写就好了,创建一个People和Student的对象,然后设置值,取值就可以了。
五。
1.构造方法没有返回值,方法名和类名一样.
2.继承是指子类可以拥有父类的方法和属性;多态是指父类的引用可以指向子类对象的实例
3.重写
4.重载
其他的没什么了,自己完成以下吧。O(∩_∩)O~
import java.io.BufferedReaderimport java.io.IOException
import java.io.InputStreamReader
public class TestString {
public static void main(String arg[]) throws IOException {
int a,n
System.out.println("请输入a,n:")
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in))
String readStr=buf.readLine()
String argStr[]=readStr.split(",")
a=Integer.parseInt(argStr[0])
n=Integer.parseInt(argStr[1])
long sum=0,aaa=0
for (int i=1i<=ni++){
aaa=(long)getaaa(a,i)
sum+=aaa
System.out.print(aaa)
if (i==n) System.out.print("=")
else System.out.print("+")
}
System.out.println(""+sum)
}
static double getaaa(int a,int n){
double aaa=a
for(double i=1i<ni++){
aaa+=a*Math.pow(10, i)
}
return aaa
}
}
需要注意的是这里面引入了几个java包。
第2个:http://zhidao.baidu.com/question/198168341.html&__bd_tkn__=6ef56e5d3a2499274a6df875f5b773e682519fb8a07960d151bbad4928e085c42f309a67e9e08f6c24eb7e11a1fbf820dff421b52a
int maxScore=experiment.getMaxAge()public int getMaxAge() {
int ages[] = new int[] { 18, 23, 21, 19, 25, 29, 17}
int max=ages[0]
for (int i = 0 i < ages.length i++) {
if (ages[i]>max) {
max=ages[i]
}
}
return max
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)