租车系统简易代码,先贴上来供大家分享,里面有可删改的地方如有需要请手动删改……遁走
http://www.imooc.com/opus/resource?opus_id=2343&tree=%2F
http://www.imooc.com/opus/resource?opus_id=2343&tree=%2F
2016-02-17
equals()通常比较对象的地址是否相同,但当我们比较对象的值是否相同,就需要在子类重写方法实现对象的属性值是否相同
2016-02-16
访问父类的属性 super.age,访问父类的方法super.age();.在对象的内部使用,可以代表父类的对象,子类的构造方法必须有调用父类的构造方法(可以不用写,写不写都有了,)如果显示调用构造方法,必须在第一行,如果子类构造方法中没有显示调用父类的构造方法,而父类又没有无参的构造方法,会出错!!!!!
2016-02-16
final最后的意思,可以修饰类,方法,属性,变量,final修饰的类不可以继承,修饰的属性不可以更改,可以在构造方法赋值,。修饰的变量为常量,修饰的方法不可以覆盖。
2016-02-16
测试类:
package com.imook3;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape shape1 = new Rectangle();
Shape shape2 = new Circle();
shape1.c();
shape1.s();
shape2.c();
shape2.s();
}
}
package com.imook3;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape shape1 = new Rectangle();
Shape shape2 = new Circle();
shape1.c();
shape1.s();
shape2.c();
shape2.s();
}
}
2016-02-14
圆形子类;
package com.imook3;
public class Circle extends Shape {
double r = 3;
public void c() {
System.out.println("圆形的周长为:" + (2 * 3.14 * r));
}
public void s() {
System.out.println("圆形的面积为:" + (3.14 * r * r));
}
}
package com.imook3;
public class Circle extends Shape {
double r = 3;
public void c() {
System.out.println("圆形的周长为:" + (2 * 3.14 * r));
}
public void s() {
System.out.println("圆形的面积为:" + (3.14 * r * r));
}
}
2016-02-14
长方形子类:
package com.imook3;
public class Rectangle extends Shape {
double a = 2;
double b = 3;
public void c() {
System.out.println("长方形的周长为:" + 2 * (a + b));
}
public void s() {
System.out.println("长方形的面积为:" + (a * b));
}
}
package com.imook3;
public class Rectangle extends Shape {
double a = 2;
double b = 3;
public void c() {
System.out.println("长方形的周长为:" + 2 * (a + b));
}
public void s() {
System.out.println("长方形的面积为:" + (a * b));
}
}
2016-02-14
父类:
package com.imook3;
public abstract class Shape {
public abstract void c();
public abstract void s();
}
package com.imook3;
public abstract class Shape {
public abstract void c();
public abstract void s();
}
2016-02-14