linkedin-skill-assessments Java 检定 static import

前言
在更新Linkedkin 个人档案的时候
偶然发现他有技术检定测验
如果总成绩在前30%,会发给你技术认证徽章
如果第一次没考过可以重考
如果第二次也没考过就要"等半年!!!" 才能考第二次
本文章为实际考题
个人感觉题目有点像OCA的考题,蛮适合正在学习Java观念
或工作一段时间但没深入研究Java的
如果有需要的人还请自行服用。

Quesion:
Normally , to acess a static member of a class such as Math.PI,
you would need to specify the class "Math". What would be the best way to allow you yo use simple "PI" in your code ?

A. Add a static import .
B. Declare local copies of the constants in your code.
C. Put the static members in an interface and inherit from that interface.
D. This cannot bedone . You must always qualify references to static memberss with the class frome which they came.

answer: A
解析:
这题目大家第一次看可能看不太懂,他的意思是如果我想直接使用Math中的PI常数,要怎麽做呢?

我们可以点进去Math这个class,可以找到PI前面宣告了static
 (话说小编只能背到3.1415926...国小老师不知道为什麽要我们背,跟弟子规一样未解之谜)


    /**
     * The {@code double} value that is closer than any other to
     * <i>pi</i>, the ratio of the circumference of a circle to its
     * diameter.
     */
    public static final double PI = 3.14159265358979323846;

而一般ide在引入static参数时,会这样建议,习惯上也会这样用:

    public static void main(String[] args) {
        System.out.println(Math.PI); //class.variable
        //印出 3.141592653589793
}

但其实也可以这样import,但比较少见

import static java.lang.Math.*;

class Main {
    public static void main(String[] args) {
        System.out.println(PI); //不须加上Math,因为在上面已经import
        //印出 3.141592653589793
    }
}

<<:  Linkedin Java 技术认证题库分享- List排序

>>:  Linkedin Java 检定题目分享

Day23 设定Alerts

今日我们要来使用Kibana内的警报功能,看如何设定Alert让我们能收到异常的通知。 设定Aler...

[Day 6] 从零开始的股票预测 - 准备资料

一、前言 在开始实验前,我们首先需要决定输入资料的型态,昨天说过了资料可分为 股价类型的「技术面」 ...

Day26 - 动态模型 part1 (LSTM)

动态模型我们会使用 LSTM-based 架构,并分成两种: Basic LSTM Last-fra...

[DAY25] Boxenn 小结

将几篇 Boxenn 相关文章整理成分类目录(范例 GitHub repository 建置中,完成...

一次一件事就好,对你而言最重要的东西是什麽?

Fake it till you make it(假装成功,直到你真的成功)。 - Emily i...