- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
考虑:
class Building {
Building() {
System.out.print("b ");
}
Building(String name) {
this();
System.out.print("bn "+name);
}
}
public class House extends Building {
House() {
System.out.print("h ");
}
House(String name) {
this();
System.out.print("hn "+name);
}
public static void main(String a[]) {
new House("x ");
}
}
对于上面的程序,我认为输出一定是h hn x。但输出为 b h hn x。
为什么?
稍后
public class TestDays {
public enum Days {
MON,TUE,WED
};
public static void main(String []args) {
for(Days d : Days.values())
;
Days [] d2=Days.values();
System.out.println(d2[2]);
}
}
我无法理解上面的程序。请帮助我。
class Mammal {
String name="furry";
String makeNoise() {
return "generic noise";
}
}
class Zebra extends Mammal {
String name="stripes";
String makeNoise() {
return "bray";
}
}
public class ZooKeeper {
public static void main(String args[]) {
new ZooKeeper().go();
}
void go() {
Mammal m=new Zebra();
System.out.println(m.name+m.makeNoise());
}
}
在上面的程序中,makeNoise() 被重写。所以输出必须是条纹。但输出是毛茸茸的叫声。
最佳答案
问题 1:
I thought the output must be h hn x. But the output comes as b h hn x.
您忽略了 House()
构造函数隐式调用 Building
的无参数构造函数这一事实。
问题2:
I cant understand the above program. Please help me.
它正在打印枚举的第三个值。空的 for 循环看起来有点奇怪,但我怀疑这只是一个打字错误。如果还有什么你不明白的地方,你就得说出来。 (我把读心 Helm 忘在家里了……乔恩·斯基特睡着了。)
问题3:
In the above program, makeNoise() is overridden. And so output must be stripes bray. But the output is furry bray.
您看到“毛茸茸”而不是“条纹”的原因是类的属性未被覆盖。 Zebra 实例实际上有两个名为 name
的字段,您的代码根据引用变量的声明类型绑定(bind)到其中之一。在本例中,m
的声明类型为 Mammal
,因此您将获得该名称的哺乳动物版本。
关于Java-SCJP 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3243068/
我之前遇到的关于 SO 的问题已经将近 2 年了。 我刚刚为 SCJP 6 购买了 Kathy Sierra 和 Bert Bates 的书。但它发生了,所以现在在我阅读博客时,我听说 SCJP“PL
嗨,我无法理解为什么输出是 'ex [6, 7, b, d] [6, 7, b]' 这段代码。请有人建议子集如何与 数字和字母?谢谢 import java.util.*; public class
在调试java多线程程序时,我设置了断点。在启动方法调用后,控件将不会运行menthod,您可以让我知道调试过程吗? 示例代码 class Test extends Thread { publ
public class Hotel { private int roomNr; public Hotel(int roomNr) { this.roomNr = ro
下面将因“标签 z 丢失”而编译失败,但如果我只是将 z: 移动到 o = o + 2 之后的下面一步,那么这会起作用吗?这背后的逻辑是什么? public class Breaker { stati
考虑: class Building { Building() { System.out.print("b "); } Building(String name
public class Starter extends Thread{ private int x = 2; public static void main(String[]
给出下面的代码。该代码由“java Test 1 2 3 4”运行。结果是什么? public class Test { public static void main(String args[])
另一个让我困惑的考试问题: public String makinStrings() { String s = “Fred”; s = s + “47”; s = s.substring(2,
我在理解 K&B 的 SCJP 书中《面向对象》一章中的问题 9 时遇到问题。 问题: public class Redwood extends Tree { public static void m
即使得到正确答案,我也无法弄清楚 SCJP 问题: 从以下代码(来源:http://scjptest.com)中,我们需要确定何时引用为 myInt 的对象符合垃圾回收条件: 01.public vo
给定: public class LineUp { public static void main(String[] args) { double d = 12.345;
只是想知道 SUN 是否提供任何可用于 SCJP 的好东西(免费或付费)??我听说微软正在提供这样的好东西。有人对此有任何想法吗? 干杯,对战 最佳答案 你可以把它写在你的简历上。大部分就是这样。 肯
这个问题来自 SCJP 转储。可能看起来很愚蠢,但我对选项有点困惑。请帮帮我 public class Donkey2 { public static void main(String[] ar
public class Person { private String name; public Person(String name) { this.name =
实际上来自SCJP 6 StudyGuide Exam310-065(MGH,2008) alt text http://www.freeimagehosting.net/uploads/1f3746
我无法理解 SCJP 书籍 K&B 第 9 章(线程)中的以下程序 问题: class Dudes{ static long flag = 0; // insert code her
Kathey Sierra 的 SCJP 书中摘录如下: If a method is overridden but you use a polymorphic (supertype) referen
public class Threads2 implements Runnable { public void run() { System.out.println("run.
这个问题是由考试实验室操纵的 public class B{ public static void main(String args[]){ byte g =10;
我是一名优秀的程序员,十分优秀!