///Animal类 package d922A; public class Animal { private String kind; public String getKind() { System.out.println(kind); return kind; } public void setKind(String kind) { this.kind = kind; } public void eat() { System.out.println("I can eat.");…
package com.hanqi.test; public class Car { //构造一个汽车的属性 private String name; //创建getter和setter方法 public String getName() { return name; } public void setName(String name) { this.name = name; } public void drive() { } } package com.hanqi.test; public c…
package zhongqiuzuoye; public class Car { String brand; public void drive() {} } package zhongqiuzuoye; public class Aodi extends Car{ public double price; public String model; public double speed; public Aodi(double price,String model,double speed)…
package b; public class Car { public final static Car pinpai=new Car(); public static Car instance() { return pinpai; } public void drive() { System.out.println("请安全驾驶!"); } } package b; public class Aodi extends Car { private String price; priv…
package animal; public class Animal { //成员属性 private String kind; public String getKind() { return kind; } public void setKind(String kind) { this.kind = kind; } //成员方法 public void eat() { } public void sleep() { } } package animal; public class Fish…
public class A { private int a=1; public int getA() { return a; } public void setA(int a) { this.a = a; } public void a() { System.out.println("a="+a); } public void c() { System.out.println("a-1="+(a-1)); } } package jicheng; public c…
编写一个Animal类,具有属性:种类:具有功能:吃.睡.定义其子类Fish package zhongqiuzuoye; public class Animal { //属性 private String type; public String getType() { return type; } public void setType(String type) { this.type = type; } //功能 public void eat() { } public void sleep…
22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表.然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法showB输出大写的英文字母表.最后编写主类C,在主类的main方法 中测试类A与类B. package jicheng; public class A { public void showA() { System.out.println("asdfsdf"); } } package jic…
这个题让我更加明白了类创建对象的实质 代码中用到:1.对象作形参;2.对象作返回值 以下用代码具体分析: class Point1{ public double x; public double y; Point1(){} public Point1(double x,double y){ this.x=x; this.y=y; } public void show(){ System.out.println("x="+x+","+"y="+y)…
//Monkey类 package d922; public class Monkey { Monkey() { } Monkey (String s) { System.out.println(s); } public void speak() { System.out.println("咿呀"); } } //人类 package d922; public class Mankind extends Monkey { public void speak() { System.out…
Print类: package com.bao; public class Print { int g,s,b; void outPut() { for(int i=100;i<1000;i++) {g=i%10; s=i/10%10; b=i/100; if(ggg+sss+bbb==i) {System.out.println(i);} } } } 主类E: package com.bao; public class E { public static void main(String[]…
package zuoye8; public abstract class Shape { private double zhouchang ; private double mianji ; public Shape(double zhouchang, double mianji) { super(); this.zhouchang = zhouchang; this.mianji = mianji; } public Shape() { super(); } //抽象一个周长方法 publi…
package shape; public class Shape { //定义成员变量 private double zhouchang; private double mianji; public double getZhouchang() { return zhouchang; } public void setZhouchang(double zhouchang) { this.zhouchang = zhouchang; } public double getMianji() { re…
package a; public class Father { public String name; private int age; public Father(String name) { this.name=name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Father(int age) { super(); this.age = age;…
i汽车类 package com.lanxi.demo2_3; public class Car { private String name; private int price; @Override//重写toString方法 public String toString() { return "Car [name=" + name + ", price=" + price + "]"; } public Car() {//创建无参构造方法 s…
package zuoye; public class print { void output() { System.out.println("100-999之间的水仙花数是:"); for(int sum=100;sum<=999;sum++) { if(Math.pow(sum/100, 3)+Math.pow(sum%10, 3)+Math.pow(sum/10%10, 3)==sum) { System.out.println(sum); } } } } package…
package b; public interface CanFly { public void fly(); } package b; public class FeiJi implements CanFly { @Override public void fly() { System.out.println("飞机 化工能源飞行"); } } package b; public class Niao implements CanFly { @Override public void…
实现多态的三个条件:1.要有继承2.要有抽象方法重写3.用父类指针(引用)指向子类对象 重载重写重定义的区别: 1.重载:在同一个类中进行; 编译时根据参数类型和个数决定方法调用; 子类无法重载父类; 父类同名方法被子类该方法覆盖. 2.重写:在父类和子类之间进行; 父类与子类方法有完全相同类型; 在运行时根据具体对象类型决定方法调用; 3.在重写中有抽象方法的会产生多态;没有使用抽象方法叫重定义 以下具体代码具体分析: package test3;abstract class Shape{ /…
求高的方法 h=y*Math.sin(a) 按题目要求,需要我们做的分别是:1.改角度2.显示角度3.求面积并显示 代码用到:1.静态成员变量以修改角度2.数学函数 以下具体代码具体分析 import java.util.Scanner; //java类库中的Scanner类,用于接受输入值 class Triangle{ private double x,y; static double a; //静态成员变量,可以用类名直接调用. Triangle(double xx,double yy,d…
注意:float虽然是4个自减,但是它的取值范围却比8个字节的long要大. float和double只能用来作科学计算或者是工程计算,但在商业计算中我们要用java.math.BigDecimal,通过使用BigDecimal类可以解决上述问题,实例代码如下: package ex;   import java.math.*;   public class BigDecimalDemo {     public static void main(String[] args){         …