Java面试问题 011-020
原文来自http://www.allapplabs.com/interview_questions/java_interview_questions.htm
翻译:Zeng Yuetian
转载请注明出处。
Q011: |
|
A: |
Some
of the collection classes provide traversal of their contents via a
java.util.Iterator interface. This interface allows you to walk through a
collection of objects, operating on each object in turn. Remember when
using Iterators that they contain a snapshot of the collection at the
time the Iterator was obtained; generally it is not advisable to modify
the collection itself while traversing an Iterator. |
Q012: |
|
A: |
Abstract
class must be extended/subclassed (to be useful). It serves as a
template. A class that is abstract may not be instantiated (ie, you may
not call its constructor), abstract class may contain static data. Any
class with an abstract method is automatically abstract itself, and must
be declared as such. |
Q013: |
|
A: |
Static
means one per class, not one for each object no matter how many
instance of a class might exist. This means that you can use them
without creating an instance of a class. Static methods are implicitly
final, because overriding is done based on the type of the object, and
static methods are attached to a class, not an object. A static method
in a superclass can be shadowed by another static method in a subclass,
as long as the original method was not declared final. However, you
can't override a static method with a nonstatic method. In other words,
you can't change a static method into an instance method in a subclass. |
Q014: |
|
A: |
A
final class can't be extended ie., final class may not be subclassed. A
final method can't be overridden when its class is inherited. You can't
change value of a final variable (is a constant). |
Q015: |
What if the main method is declared as private? |
A: |
The program compiles properly but at runtime it will give "Main method not public." message. |
Q016: |
What if the static modifier is removed from the signature of the main method? |
A: |
Program compiles. But at runtime throws an error "NoSuchMethodError". |
Q017: |
What if I write static public void instead of public static void? |
A: |
Program compiles and runs properly. |
Q018: |
What if I do not provide the String array as the argument to the method? |
A: |
Program compiles but throws a runtime error "NoSuchMethodError". |
Q019: |
What is the first argument of the String array in main method? |
A: |
The String array
is empty. It does not have any element. This is unlike C/C++ where the
first element by default is the program name. |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)