【分录题】(7-1)请阅读下面程序,并写出运行结果。 class Base{ public int getX() { return 1; } public static int getY() { return 2; } } class Sub extends Base{ public int getX() { return 3; } public static int getY() { return 4; } } public class Demo { public static void main(String[] args) { Sub sub=new Sub(); Base base=(Base) sub; int a=sub.getX()*base.getX(); int b=sub.getY()+base.getY(); System.out.println(a+b); } }
第1题
【分录题】(7-12)请阅读程序,写出程序运行结果。 class A{ static String name="tom"; static int getX() { return 2; } int getY() { return 3; } } class B extends A{ static String name="Tuny"; static int getX() { return 4; } int getY() { return 5; } } class C extends A{ static String name="Tuny"; static int getX() { return 4; } int getY() { return 5; } } interface D{ int getY(); } class E implements D{ public int getY() { return 6; } } public class Demo{ public static void main(String[] args) { A a=new A(); A b=new B(); A c=new C(); D d=new E(); int sum=a.name.length()+b.getX()+c.getY()+d.getY(); System.out.println(sum); } }
第2题
第3题
A.375
B.357
C.0375
D.0357
第4题
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!