• 2021-04-14
    读程序,写出和程序输出格式一致的输出结果。
    public class J_Test {
    public static void mb_method(int i) {
    try {
    if(i == 1)
    throw new Exception();
    System.out.print("1");
    }
    catch(Exception ex) {
    System.out.print("2");
    return;
    }
    finally {
    System.out.print("3");
    }
    System.out.print("4");
    }
    public static void main(String[] args) {
    mb_method(0);
    mb_method(1);
    }
    }
  • 13423

    举一反三

    内容

    • 0

      以下程序的输出结果为?public class Test {public static void main(String args[]) {for ( int k = 0; k < 3; k++)System.out.print("k");}}

    • 1

      以下程序的运行结果是:() public class Increment{ public static void main(String args[]) { int a; a = 6; System.out.print(a); System.out.print(a++); System.out.print(a); } }

    • 2

      请说出下列程序的输出结果_____________,_____________。import java.io.IOException;public class E {public static void main(String args&#91;&#93;){try { methodA();}catch(IOException e){System.out.print("你好");return;}finally {System.out.println("thanks");}}public static void methodA() throws IOException{throw new IOException();}}

    • 3

      请写出以下程序运行结果: public class Main { public Main() { System.out.print("main "); } public Main(String s) { this(); System.out.print("main with "+s); } public static void main(String[] args) { Main main = new Main("wow"); } }

    • 4

      import java.io.*; class Person{ public void print(){System.out.print("Person ");} public void printMyGender(String s){ this.print(); System.out.print(s+" "); } } class Gender{ String type="gender"; public void print(Person p){p.printMyGender(type);} } class Female extends Gender{ public Female(){ type="female"; } } class Male extends Gender{ public Male(){ type="male"; } } class Employee extends Person{ public void print(){ System.out.print("Employee ");} } class Manager extends Employee{ public void print(){ System.out.print("Manager ");} } public class Test{ public static void main(String[] args){ Manager man = new Manager(); Employee em = new Employee(); Gender gender1 = new Male(); Gender gender2 = new Female(); gender1.print(man); gender2.print(em); } } 对于以上代码,其运行结果是