boolean(布尔型) 是用来存储真值或者假值的数据类型..
在实际中怎么应用呢\?比如下题....我该怎么确定某动物是不是肉食动物 ?..
ps :还没做完...在线等高手指点下=。=
public class Animal {
boolean mammal;
boolean carnivorous;
int mood;
String dongwu;
public Animal(){
}
void isMammal(){
System.out.println(dongwu+?+"哺乳动物");
}
void isCarnivorous(){
System.out.println(dongwu+?+"肉食动物");
}
void setMood(int newValue){
}
void getMood(){
}
void sayHello(){
}
public static void main(String[] args) {
Animal a = new Dog();
a.dongwu="狗";
a.isMammal();
a.isCarnivorous();
Animal b = new Cat();
b.dongwu="猫";
b.isMammal();
b.isCarnivorous();
Animal c = new Frog();
c.dongwu="青蛙";
c.isMammal();
c.isCarnivorous();
}
}
interface LandAnimal{
void getNumberOfLegs();
}
interface WaterAnimal{
void hasGills();
void laysEggs();
}
class Dog extends Animal{
int numberOfLegs;
Dog(){
}
void SayHello(){
}
void sayHello(int newValue){
}
void getNumberOfLegs(){
}
}
class Cat extends Animal{
int numberOfLegs;
Cat(){
}
void SayHello(){
}
void sayHello(int newValue){
}
void getNumberOfLegs(){
}
}
class Frog extends Animal{
int numberOfLegs;
Frog(){
}
void SayHello(){
}
void sayHello(int newValue){
}
void getNumberOfLegs(){
}
void hasGills(){
}
void laysEggs(){
}
}
[此贴子已经被作者于2007-4-29 16:30:12编辑过]