演示Java的静态导入
静态导入是Java版本5及更高版本中引入的功能。这意味着,如果将类中的字段和方法定义为公共静态,则无需指定其类即可在代码中使用它们。
给出了一个用Java演示此程序的程序,如下所示:
示例
import static java.lang.System.*;
public class Demo {
public static void main(String args[]) {
out.println("Demonstration of Static Import in Java");
int a = 10;
out.println("Value of a is: " + a);
}
}输出结果
Demonstration of Static Import in Java Value of a is: 10
现在让我们了解上面的程序。
System.out.println()中不需要System类,因为java.lang包使用了静态导入。因此,无需将System类指定为使用System类的out成员字段和println方法。演示此代码段如下:
out.println("Demonstration of Static Import in Java");
int a = 10;
out.println("Value of a is: " + a);热门推荐
10 高一祝福语简短 励志
11 立秋节气简短祝福语
12 简短公司周年祝福语大全
13 中考感言简短祝福语大全
14 体育老师简短祝福语
15 干杯生日祝福语简短独特
16 特别简短的祝福语老师
17 朋友坐车走了祝福语简短
18 给英雄的祝福语简短