java面试题 英文

编程入门 行业动态 更新时间:2024-10-17 15:21:48

java面试题 <a href=https://www.elefans.com/category/jswz/34/1769696.html style=英文"/>

java面试题 英文

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

Q: What is an abstract class?

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.

A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

Q: What is static in java?

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.

Q: What is final?

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).

Q: 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.

Q: What if the static modifier is removed from the signature of the main method?

A: Program compiles. But at runtime throws an error “NoSuchMethodError”.

Q: What if I write static public void instead of public static void?

A: Program compiles and runs properly.

Q: What if I do not provide the String array as the argument to the method?

A: Program compiles but throws a runtime error “NoSuchMethodError”.

Q: 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.

Q: If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?

A: It is empty. But not null.

更多推荐

java面试题 英文

本文发布于:2024-02-07 01:59:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1752282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:英文   面试题   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!