這個(gè)沒有什么創(chuàng)新,只是有可能寫法不一樣而已。但基本思路都是這樣寫的
創(chuàng)新互聯(lián)公司"三網(wǎng)合一"的企業(yè)建站思路。企業(yè)可建設(shè)擁有電腦版、微信版、手機(jī)版的企業(yè)網(wǎng)站。實(shí)現(xiàn)跨屏營銷,產(chǎn)品發(fā)布一步更新,電腦網(wǎng)絡(luò)+移動(dòng)網(wǎng)絡(luò)一網(wǎng)打盡,滿足企業(yè)的營銷需求!創(chuàng)新互聯(lián)公司具備承接各種類型的網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)項(xiàng)目的能力。經(jīng)過10年的努力的開拓,為不同行業(yè)的企事業(yè)單位提供了優(yōu)質(zhì)的服務(wù),并獲得了客戶的一致好評。
測試類用到了多態(tài)
import java.util.ArrayList;
import java.util.List;
public class Test {// 測試類
public static void main(String[] args) throws Exception {
ListAnimal animals=new ArrayListAnimal();
animals.add(new Dog());//一只狗
animals.add(new Cat());//一只貓
animals.add(new Frog());//一只青蛙
for (Animal animal : animals) {//遍歷
System.out.println(animal);//一個(gè)動(dòng)物的描述
animal.say();//打招呼
animal.happy();//情緒好
animal.afraid();//害怕
System.out.println("------------可愛的分割線------------");
}
}
}
class Animal {
boolean isLusheng = false;
boolean isShuisheng = false;
boolean isRoushi = false;
boolean isBuru = false;
public void say() {
}
public void happy() {
}
public void afraid() {
}
public String toString() {
return (isLusheng ? "是" : "非") + "陸生,"
+ (isShuisheng ? "是" : "非") + "水生,"
+(isRoushi ? "是" : "非") + "肉食,"
+(isBuru ? "是" : "非") + "哺乳";
}
}
class Dog extends Animal {
public Dog() {
isLusheng = true;
isRoushi = true;
isBuru = true;
}
public void say() {
System.out.println("搖搖尾巴");
}
public void happy() {
System.out.println("旺旺叫");
}
public void afraid() {
System.out.println("嗚嗚");
}
}
class Cat extends Animal {
public Cat() {
isLusheng = true;
isRoushi = true;
isBuru = true;
}
public void say() {
System.out.println("喵~");
}
public void happy() {
System.out.println("咕嚕咕嚕");
}
public void afraid() {
System.out.println("嘶嘶");
}
}
class Frog extends Animal {
boolean isRuansheng=true;
public Frog() {
isLusheng = true;
isShuisheng = true;
}
public void happy() {
System.out.println("呱呱呱");
}
public void afraid() {
System.out.println("撲通一聲跳入水中");
}
public String toString() {
return super.toString()+","
+(isRuansheng ? "是" : "非") + "卵生";
}
}
有問題追問,或HI我
先把這里的dog類注釋掉,然后查看程序Dog wangwang = new Dog("wangwang",15);中dog的定義是否存在。(右鍵Dog,查看定義)
public static void main(String[] args) {
int i = 0;
while (i 100){
System.out.println("我喜歡你");
i++;
}
}