题目内容
(请给出正确答案)
[主观题]
阅读下面的程序, 分析代码是否能够编译通过 class A { private int secret = 5; } public class Test1 { public static void main(); } }
A.可以编译通过
B.不能编译通过
提问人:网友lixin080108
发布时间:2022-01-07
A.可以编译通过
B.不能编译通过
阅读下面的程序,分析代码是否能够编译通过,如果能编译通过,请列出运行的结果。否则请说明编译 失败的原因。 public class Demo { public static void main(String[] args) { Base b1=Base.getBaseInstance1(); System.out.print(b1.getS()); Base b2=Base.getBaseInstance2(); System.out.print(b2.getS()); } } abstract class Base { private static String s = "base"; public static Base getBaseInstance1() { return new Base() { public String getS() { return s; } }; } public static Base getBaseInstance2() { return new Base("good") { public String getS() { return s; } }; } public Base() { } public Base(String s) { this.s = s; } public abstract String getS(); }
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!