zoukankan      html  css  js  c++  java
  • 【笔试题】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 ```
  • 相关阅读:
    adb monkey测试 命令
    大数据 入门
    代码设计模式 编写思想 架构
    汉化 android studio
    电脑时间显示秒 win10电脑显示农历
    Restful api介绍
    Map工具系列-03-代码生成BySQl工具使用说明
    win10 office2013激活工具
    win10 1607 密匙
    .net社区
  • 原文地址:https://www.cnblogs.com/hgnulb/p/11294583.html
Copyright © 2011-2022 走看看