相关文章
更多最近更新
更多请教两个JAVA问题
2019-03-25 13:35|来源: 网路
第一题:(答案:F)
Given the following method signatures from ArrayList:
boolean add(E e)
protected void removeRange(int fromIndexInclusive, int toIndexExclusive)
int size()
and given:
2. import java.util.*; 3. public class MyUtil extends ArrayList { 4. public static void main(String[] args) { 5. MyUtil m = new MyUtil(); 6. m.add("w"); m.add("x"); m.add("y"); m.add("z"); 7. m.removeRange(1,3); 8. System.out.print(m.size() + " "); 9. MyUtil m2 = new MyUtil2().go(); 10. System.out.println(m2.size()); 11. } 12. } 13. class MyUtil2 { 14. MyUtil go() { 15. MyUtil m2 = new MyUtil(); 16. m2.add("1"); m2.add("2"); m2.add("3"); 17. m2.removeRange(1,2); 18. return m2; 19. } }
What is the result?
A. 1 1
B. 1 2
C. 2 1
D. 2 2
E. An exception is thrown at runtime.
F. Compilation fails due to a single error.
G. Compilation fails due to multiple errors.
第二题:(答案:F)
Given:
1. public class Hose <E extends Hose> { 2. E innerE; 3. public static E doStuff(E e, Hose<E> e2) { 4. // insert code here 5. } 6. public E getE() { 7. return innerE; 8. } }
Which can be inserted, independently at line 4, for the code to compile? (Choose all that apply.)
A. return e;
B. return e.getE();
C. return e2;
D. return e2.getE();
E. return new Hose().getE();
F. Compilation fails regardless of which return is inserted.
请大家帮忙解释下原因,多谢啦!
问题补充:第一题:removeRange是protected方法没错,但是在MyUtil2中调用这个方法的还是MyUtil的对象呀。MyUtil m2 = new MyUtil(); .......; m2.removeRange(1,2); 这跟在MyUtil自己的main方法中调用不是一样的吗?
比如这样:
class A {
protected void foo() {}
}
class B extends A {
}
class C {
void bar() {
B b = new B();
b.foo(); // 这里也是在子类之外,却是可以调用的。
}
}
第2题:
如果去掉static的话,答案是AD,好费解哦,为什么是AD呢?
还请大家多多帮忙!
相关问答
更多-
请教在温州:去手机维修培训学校两个月可以学好手机维修吗,一般有没有安排工作的吗?[2023-02-13]
可以学会,但以后自己慢慢搞,就会精了,没有安排工作的 -
用java实现两个文档的互拷 要求有例子[2021-11-14]
 .nio.getChannel(), targetChannel = new FileOutputStream(target) 最简单又可靠的方法是利用一个临时文件(模式就跟利用临时变量的变量值交换一样).out.getChannel(); sourceChannel.transferTo(0;); + e.getMessage()); }  .println("temp.deleteOnExit(); public static void main(String[] args) { } ... -
请教一下同时会yii和thinkphp这两个框架的大神,你喜欢用哪个框架呀? 谁能回答我啊[2022-01-07]
TP是个简单 容易上手的框架 YII比较强大 相对来说 难度也比TP高 这用哪个看你自己兴趣吧 还要看公司需求 本人一直用TP -
TOMCAT如何部署两个java web项目[2022-03-08]
1、可以使用集群方式来部署 2、集群方式可以采用nginx+tomcat方式来部署两个或者多个Java web项目 原理: 1、nginx作为集群,能够通过给出多个端口号来配合tomcat一起使用 2、有了多个端口号,那么Java项目即可通过不同的端口来进行访问 -
请教两个关于使用 python 爬去哪儿,携程等机票网站的问题[2022-03-19]
这个不一定的,需要交叉去对比,有时候去哪儿便宜,有时候携程便宜。顺便您要知道一下去哪儿和携程是合并的,也算一家,只是平台不一样。去哪儿和携程很多机票不是自己在卖,都是航空公司的代理商在卖,就等于以前的店面操作换到了网上多处销售,有专门的的工作人员根据当日实时机票销售情况,网络后台随时调整价格,所以建议您要交叉对比,不能说哪个好,哪个不好,哪个更便宜。希望我的回答可以帮到您,祝您生活愉快。 -
请教:单元测试框架使用cppunit,请问那么如何进行两个模块的接[2022-12-14]
这个提问,好不清晰。。。不过,偶给自己顶一下。。。应该说:如何使用cppunit进行接口测试?发给范例给偶,就好了。实乃万分感激。。。 -
请教,Java版的QQ能否后台运行?[2022-12-04]
QUOTE:原帖由 joncjq 于 2009-12-2 15:09 发表 screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new windownCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width ... -
Java中的“Iterable”和“Iterator”这两个单词的正确读音是什么,详见问题内容。[2024-02-03]
iterable['itəreibl]:重音在['i] 可迭代的 iterator['itəreitə]:重音在['i] 迭代器 -
比较两个向量(Java)(Compare Two Vectors (Java))[2022-04-12]
看看Lucene中的相似度函数 。 上述公式是由文档和查询向量之间的余弦距离或点积产生的 这是关于此主题的前一个SO问题 。 Have a look at the similarity function in Lucene. the above formula is motivated by the cosine-distance or dot-product between document and query vector Here's a Previous SO question on this to ... -
两个Java类的比较(Comparison of two Java classes)[2023-09-20]
在没有调试信息的情况下编译这两个类,然后将它们反编译回源文件。 反编译的文件应该比原始源文件更相似。 您可以通过对已编译的文件运行一些优化来进一步改进。 例如,您可以使用Proguard启用缩小功能来删除未使用的代码。 但是,某些陈述的位置变化很难被发现。 Compile both of the classes without debug information and then decompile them back to source files. The decompiled files should ...