笔试题Java final keyword

Posted hglibin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了笔试题Java final keyword相关的知识,希望对你有一定的参考价值。

Java 知识测试 Java final keyword
Question 1
What is the use of final keyword in Java?
A. When a class is made final, a sublcass of it can not be created.
B. When a method is final, it can not be overridden.
C. When a variable is final, it can be assigned value only once.
D. All of the above

参考答案

D

Question 2
Output of follwoing Java program

class Main 
    public static void main(String args[]) 
        final int i;
        i = 20;
        System.out.println(i);
    

A. 20
B. Compiler Error
C. 0
D. Garbage value

参考答案

A

Question 3

class Main 
    public static void main(String args[]) 
        final int i;
        i = 20;
        i = 30;
        System.out.println(i);
    

A. 30
B. Compiler Error
C. Garbage value
D. 0

参考答案

B

Question 4

class Base 
    public final void show() 
        System.out.println("Base::show() called");
    


class Derived extends Base 
    public void show() 
        System.out.println("Derived::show() called");
    


public class Main 
    public static void main(String[] args) 
        Base b = new Derived();
        b.show();
    

A. Derived::show() called
B. Base::show() called
C. Compiler Error
D. Exception

参考答案

C

以上是关于笔试题Java final keyword的主要内容,如果未能解决你的问题,请参考以下文章

java常见面试题——java笔试题总结

java常见面试题——java常见笔试题

java笔试题

Java精选笔试题

2021年阿里腾讯字节等大厂技术面试题汇总,西安富士通Java笔试题

2015搜狐在线笔试题(内存泄露问题)(转)