演示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 教师闺蜜祝福语简短