【Java开源代码栏目提醒】:网学会员在Java开源代码频道为大家收集整理了VariableScope.java提供大家参考,希望对大家有所帮助!
public class VariableScope {
// 定义类的常量
static final String SLOGAN_CN = "同一个世界 同一个梦想";
static final String SLOGAN_EN = "One World One Dream";
// 定义成员变量
static String mascots1 = "北", mascots2 = "京";
static String mascots3 = "欢", mascots4 = "迎";
static String mascots5 = "你";
public static void languageEn() {
// 定义局部变量
String mascots1 = "Beibei", mascots2 = "Jingjing";
String mascots3 = "Huanhuan", mascots4 = "Yingying";
String mascots5 = "Nini";
System.out.println(SLOGAN_EN);
System.out.print(mascots1 + " " + mascots2 + " ");
System.out.print(mascots3 + " " + mascots4 + " ");
System.out.println(mascots5 + " ");
}
public static void languageCn() {
// 定义局部变量
String mascots1 = "贝贝", mascots2 = "晶晶";
String mascots3 = "欢欢", mascots4 = "迎迎";
String mascots5 = "妮妮";
System.out.println(SLOGAN_CN);
System.out.print(mascots1 + " " + mascots2 + " ");
System.out.print(mascots3 + " " + mascots4 + " ");
System.out.println(mascots5 + " ");
}
public static void main(String[] args) {
languageCn(); // 调用languageCn()方法
languageEn(); // 调用languageEn()方法
System.out.print(mascots1 + " " + mascots2 + " ");
System.out.print(mascots3 + " " + mascots4 + " ");
System.out.println(mascots5 + " ");
}
}