皮皮学,免费搜题
登录
搜题
【简答题】
现需要设计一个可以模拟各种动物行为的机器人,在机器人中定义了一系列方法,如机器人叫喊方法cry()、机器人移动方法move()等。如果希望在不修改已有代码的基础上使得机器人能够像狗dog一样叫wang(),像狗一样跑run(),使用 1 模式进行系统设计。 import javax.xml.parsers.*; import org.w3c.dom.*; import org.xml.sax.SAXException; import java.io.*; public class XMLUtil { // 该方法用于从 XML 配置文件中提取具体类类名,并返回一个实例对象 public static Object getBean() { try { // 创建文档对象 DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document doc; doc = builder.parse(new File("config.xml")); // 获取包含类名的文本节点 NodeList nl = doc.getElementsByTagName("className"); Node classNode=nl.item(0).getFirstChild(); String cName=classNode.getNodeValue(); // 通过类名生成实例对象并将其返回 Class c=Class.forName(cName); Object obj=c.newInstance(); return obj; } catch(Exception e) { e.printStackTrace(); return null; } } } public class Client { public static void main(String args[]) { Robot robot=(Robot)XMLUtil. 2 ; robot.cry(); robot.move(); } } public class Bird { public void tweedle() { System.out.println(" 鸟儿叽叽叫! "); } public void fly() { System.out.println(" 鸟儿快快飞! "); } } public interface Robot { public void cry(); public void move(); } public class BirdAdapter extends Bird implements 3 { public void cry() { System.out.print(" 机器人模仿: "); super.tweedle(); } public void move() { System.out.print(" 机器人模仿: "); super.fly(); } } public class Dog { public void wang() { System.out.println(" 狗汪汪叫! "); } public void run() { System.out.println(" 狗快快跑! "); } } public class DogAdapter extends Dog implements Robot { public void cry() { System.out.print(" 机器人模仿: "); super. 4 ; } public void 5 { System.out.print(" 机器人模仿: "); super.run(); } }
拍照语音搜题,微信中搜索"皮皮学"使用
参考答案:
参考解析:
知识点:
.
..
皮皮学刷刷变学霸
举一反三
【单选题】多个音高相同的音符要唱(奏)成一个音,所用的记号是
A.
增时线
B.
延长号
C.
附点
D.
延音线
【单选题】Practising Chinese Kung fu can not only _____ one’s strength, but also develop one’s character.
A.
bring up
B.
take up
C.
build up
D.
put up
【单选题】_____ refers to a character who represents only one quality, either good or bad, and who can always be counted on to act the same way.
A.
Round character
B.
Flat character
C.
Dynamic
D.
Major character
【单选题】A character can best be defined as
A.
A real person who acts in a play.
B.
The people who talk in a book.
C.
Any person, animal, creature, being, or thing in a story.
D.
Only the people in a story.
【判断题】A character can only have one tone in Chinese.
A.
正确
B.
错误
【简答题】( )根据其网络层地址来实现数据包路由选择的设备。 a.网桥 b.路由器 c.中继器 d.以上都不是A. b.路由器
【单选题】( )根据其网络层地址来实现数据包路由的设备。
A.
网桥
B.
路由器
C.
中继器
D.
以上都不是
【单选题】()根据其网络层地址来实现数据包路由的设备。
A.
网桥
B.
网关
C.
中继器
D.
路由器
【判断题】In the 3rd person omniscient POV, the character can only know the thoughts and feelings of one character.
A.
正确
B.
错误
【单选题】Practising Chinese kungfu (功夫)can not only ____ one’s strength, but also develop one’s character.
A.
bring up
B.
take up
C.
build up
D.
pull up
相关题目: