⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex11(3).java

📁 JAVA编程思想第四版英文原版习题答案. pdf原版的
💻 JAVA
字号:
// typeinfo/Ex11.java
// TIJ4 Chapter Typeinfo, Exercise 11, page 582
// Add Gerbil to the typeinfo.pets library and modify all the examples
// in this chapter to adapt to this new class.
import typeinfo.pets.*;
import net.mindview.util.*;
import static net.mindview.util.Print.*;

/* 	
	// Made following additions:
	// typeinfo.pets package:
	// typeinfo/pets/Gerbil.java
	package typeinfo.pets;
	public class Gerbil extends Rodent {
		public Gerbil(String name) { super(name); }
		public Gerbil() { super(); }
	} 
	// ForNameCreator.java
	"typeinfo.pets.Gerbil" 
	// PetCount.java
	if(pet instanceof Gerbil) counter.count("Gerbil"); 
	// LiteralPetCreator.java
	Gerbil.class 
*/

public class Ex11 {
	public static void main(String[] args) {
		TypeCounter counter = new TypeCounter(Pet.class);
		for(Pet pet : Pets.createArray(20)) {
			printnb(pet.getClass().getSimpleName() + " ");
			counter.count(pet);
		}	
		print();
		print(counter);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -