阅读程序题(给出【代码】注释标注的代码的输出结果)class A {int f(int x,int y) { return x + y;}}class B extends A {int f(int x, int y) {int m = super.f(x,y) + 10;return m;}}public class习题5_阅读1 {public static void main(String args[ ]) {A a = new B();System.out.println(a.f(2,10)); //【代码】}}
查看答案
阅读程序题(给出【代码】注释标注的代码的输出结果)class Animal { int m = 100;public int seeM() { return m;}public int getM() { return m;}}class Dog extends Animal {int m = 6;public int seeM() { return m;}}public class 习题5_阅读2 {public static void main (String args[ ]){Animal animal = null;Dog dog = new Dog();animal = dog;System.out.printf("%d:%d:%d",dog.seeM(),animal.seeM(),animal.getM( ));//【代码】}}
阅读程序题(给出【代码】注释标注的代码的输出结果)interface Com {int add( int a, int b);}abstract class People {abstract int add( int a, int b);}class Student extends People implements Com{public int add(int a,int b) {return a + b;}}public class 习题5_阅读3 {public static void main(String args[ ]) {Student stu = new Student ();Com com = stu;int m = com.add(12,6);People p = stu;int n = p.add(12,8);System.out.printf("%d:%d",m,n); //【代码】}}
阅读程序题(给出【代码】注释标注的代码的输出结果)interface Com {int add(int a, int b);public static int get(int n){return n;}public default int see( int n){return n;}public default int look( int n) {return n;}}class A implements Com{public int add( int a, int b) { return a + b;}public int see(int n){ return n + 1;}}public class 习题5_阅读4{public static void main( String args[ ]) {A a = new A();int m = a.add(12,6);int n = Com.get( 12);int t = a.see(6);int q = a.look(6);System.out.printf("%d:%d:%d:%d",m,n, t,q); //【代码】 }}}
阅读程序,写出其输出结果:class ScoreException extends Exception{int m;ScoreException(int m){this.m =m;}int getMess( ){return m;}}class Teacher{public int giveScore(int score)throws ScoreException{if(score > 100 || score<0)throw new ScoreException(score);return score;}}public class E{public static void main(String args[ ]){Teacher t = new Teacher( );int m =0,n=0;try{m = t.giveScore(100);m = t.giveScore(101);}catch(ScoreException e){n = e.getMess( );}System.out.printf("%d:%d",m,n);}}