题目内容

请写出以下程序在控制台的输出。class Super{static String greeting(){ return "Good night"; }String name(){ return "Tom"; }}class Sub extends Super{static String greeting(){ return "Hello"; }String name(){ return "Mary"; }}public class test{public static void main(String[] args){Super s = new Sub();System.out.println( s.greeting() +"," + s.name() );}}

查看答案
更多问题

请写出以下程序在控制台的输出。interface InTest{ void testPrintln(); void lambda(); }class Outer implements InTest{public void testPrintln(){ System.out.println("One"); }public void lambda(){ System.out.println("Outer"); testPrintln(); }}public class TestInner {static class Inner extends Outer{public void testPrintln(){ System.out.println("Two"); }public void lambda(){ System.out.println("Inner" ); testPrintln(); }}public static void main(String[]args){InTest tmp =new Outer();tmp.lambda();tmp=new Inner(); tmp.lambda();tmp =new Outer(){public void testPrintln(){ System.out.println("Three");}public void lambda(){System.out.println("Annoy" );super.testPrintln();}};tmp.lambda();}}

请写出下面程序的运行结果class A {public A() {System.out.print("1");}static { System.out.print("2"); }}class B extends A {public B() {System.out.print("3");}static { System.out.print("4"); }}public class test {public static void main(String[] args) {new B();}}

请写出下面程序的运行结果class A {public static String staticGet() {return "1"; }public String dynamicGet() {return "2"; }}class B extends A {public static String staticGet() {return "3"; }public String dynamicGet() {return "4"; }}public class test {public static void main(String[] args) {A a = new B();System.out.print( a.staticGet() );System.out.print( a.dynamicGet() );}}

请写出下面程序的运行结果classMyExceptionextendsException{publicStringtoString(){return"negative";}}publicclassExceptionDemo{publicstaticfloatmySqrt(inta)throwsMyException{if(a<0)thrownewMyException();elsereturn Math.sqrt(a);}publicstaticvoidmain(Stringargs[]){try{mySqrt(-5);}catch(MyExceptione){System.out.println("Caught"+e);}}}

答案查题题库