云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 精品文档java面向对象习题

精品文档java面向对象习题

  • 62 次阅读
  • 3 次下载
  • 2025/5/1 8:03:44

What is the output? A. 4, 4 B. 4, 5 C. 5, 4 D. 5, 5 E. Compilation fails. class A { public A () { System.out.println (\ } } class B extends A { public B () { System.out.println (\ super(); } } public class Test { public static void main (String args []) { A a = new B(); } } What is the result when main is executed? A. Compilation fails. B. hello from a C. hello from b D. hello from b hello from a E. hello from a hello from b class super ( public int I = 0; public super (string text) ( I = 1; ) ) public class sub extends super ( public sub (string text) ( i= 2; )

public static void main (string args[]) ( sub sub = new sub (\ system.out. PrintIn(sub.i); ) ) What is the result? A. Compilation will fail. B. Compilation will succeed and the program will print \C. Compilation will succeed and the program will print \D. Compilation will succeed and the program will print \ 链表练习

使用链表完成Stack和Queue

高级类特性

学习Singleton用法(static)

写一个代码片断,用下面的格式打印出2008年所有星期日的日期。(Calendar) 2008年1月6日 2008年1月13日

Objective In this exercise you will create a hierarchy of animals that is rooted in an abstract class Animal. Several of the animal classes will implement an interface called Pet. You will experiment with variations of these animals, their methods, and polymorphism. Directions 1. Create the Animal class, which is the abstract superclass of all animals. 1. Declare a protected integer attribute called legs, which records the number of legs for this animal. 2. Define a protected constructor that initializes the legs attribute. 3. Declare an abstract method eat. 4. Declare a concrete method walk that prints out something about how the animals walks (include the number of legs). 2. Create the Spider class. 1. The Spider class extends the Animal class. 2. Define a default constructor that calls the superclass constructor to specify that all spiders have eight legs. 3. Implement the eat method. 3. Create the Pet interface specified by the UML diagram.

4. Create the Cat class that extends Animal and implements Pet. 1. This class must include a String attribute to store the name of the pet. 2. Define a constructor that takes one String parameter that specifies the cat's name. This constructor must also call the superclass constructor to specify that all cats have four legs. 3. Define another constructor that takes no parameters. Have this constructor call the previous constructor (using the this keyword) and pass an empty string as the argument. 4. Implement the Pet interface methods. 5. Implement the eat method. 5. Create the Fish class. Override the Animal methods to specify that fish can't walk and don't have legs. 6. Create an TestAnimals program. Have the main method create and manipulate instances of the classes you created above. Start with: Fish d = new Fish(); Cat c = new Cat(\Animal a = new Fish(); Animal e = new Spider(); Pet p = new Cat(); Experiment by: a) calling the methods in each object, b) casting objects, c) using polymorphism, and d) using super to call super class methods. What is the result of the following code : public class SuperEx { String r; String s; public SuperEx(String a,String b) { r = a; s = b; } public void aMethod() { System.out.println(\ }

搜索更多关于: 精品文档java面向对象习题 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

What is the output? A. 4, 4 B. 4, 5 C. 5, 4 D. 5, 5 E. Compilation fails. class A { public A () { System.out.println (\ } } class B extends A { public B () { System.out.println (\ super(); } } public class Test { public static void main (String args []) { A a = new B(); } } What is the result when main is executed? A. Compilation fails. B. hello from a C. hello from b D. hello from

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com