- 博客(7)
- 收藏
- 关注
原创 继承
public class Person {//定义类 protected String name; protected int age; public void Say(){ System.out.println(name+"can say"); } public void setName(String name){ this.name=name; //??? } } (新类
2017-09-12 21:21:32
248
转载 使用类
/*使用类成员*/ public class MyClass { //构造类 static int statInt=4; //定义静态变量 static double statDouble=16.0; int instInt; //定义变量 double instDouble; public static void staticMethod(){ System.out.prin
2017-09-12 16:44:21
294
转载 使用对象
/*使用对象通过点运算来实现 格式如 对象名.成员变量名,对象名.成员方法(参数列表), * 调用时要指定调用的方法名,实参,并要求实参类型,个数和顺序与定义中的形参一致*/ public class PassTest { //定义类PassTest float ptValue; //定义变量 public void changeInt(int value){ //构造函数,传入参
2017-09-11 21:44:25
334
转载 构造方法重载
/*构造函数重载*/ public class Stu { int no ; //定义变量 String name; Stu(String l_name){ //构造函数,传入参数 no=0; name=l_name; //初始化变量 } Stu(int l_no, String l_name){ //重载函数Stu,传入参数两个 no=l_no;name=l_name;
2017-09-11 19:34:45
512
转载 初始化对象
/*初始化对象(在定义成员变量时对其赋值)*/ public class Student {//定义类Student int no; //定义变量no String name; //定义变量name Student(int l_no, String l_name){ //构造函数Student,传入形参两个 no=l_no;name=l_name; //初始化变量no,nam
2017-09-11 19:33:21
321
原创 方法重载
方法重载 public class Circle { float x,y; //定义变量x y float radius; //定义变量 radius double getArea(){ //构造面积计算函数 return radius*radius*3.14; //返回与getArea } double getCircumference(){ //构造周长函数 re
2017-09-11 19:31:59
278
原创 使用类和对象
定义类Circle,计算面积与周长 public class Circle { float x,y; //定义变量x y float radius; //定义变量 radius double getArea(){ //构造面积计算函数 return radius*radius*3.14; //返回与getArea } double getCircumference(){
2017-09-11 16:52:33
232
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅