收藏 分销(赏)

JAVA模拟考试(答案).doc

上传人:s4****5z 文档编号:8792918 上传时间:2025-03-02 格式:DOC 页数:8 大小:78.50KB 下载积分:10 金币
下载 相关 举报
JAVA模拟考试(答案).doc_第1页
第1页 / 共8页
JAVA模拟考试(答案).doc_第2页
第2页 / 共8页


点击查看更多>>
资源描述
Java模拟考试 一 、名词解释 1、 java的三个基本特征,并加以解释 2、 从用户的角度看,Java源程序中的类分为哪两种? 3 解释this,super的使用场合 4、在java语言说明类的成员有哪四种级别的访问控制? 5、说明重载与覆盖的区别? 6、在java语言中写出定义类的最一般形式 7、类修饰符用于指定类的使用特性和访问权限,通常有哪几种? 8、简单说明静态成员变量的特征? 二、选择题 1、下面程序段的输出结果是:   int  a = 3;   System.out.print( a++);   System.out.print( a);   System.out.print(++a);   A.444      B.445    C. 345   D.344 结果: 2、以下哪些是基本数据类型? A.byte B. String C. integer D. Float 结果: 3、选择以下程序运行结果 System.out.println(" " +4 + 5;   System.out.println(4 + 5);   System.out.println(4 + 5 +"");   System.out.println(4 + "" +5);     A.第3行出现编译错误 B.输出45, 7, 7 和45. C.输出7, 7, 7 和45. D.输出 45, 7, 45 和45. 结果: 4、选择以下程序运行结果 public class test {    public static void main(String args[]) {     int x=2,y=2,z=2;     if  (x-- == 1 && y++ == 1 || z++ == 1)        System.out.println("x=" + x + ",y=" + y + ",z=" + z);     }  } A. x=1,y=3,z=2 B. x=2,y=3,z=2 C. x=1,y=2,z=2 D. x=1,y=3,z=3 结果: 5、 编译和运行以下代码结果为: public class EqualsTest{   public static void main(String args[]){ byte A=(byte)4096;     if(A==4096) System.out.println("Equal");      else System.out.println("Not Equal"); } } A.在第3行出现转换丢失精度的编译错误. B.输出 "Not Equal". C.输出 “Equal“. D. 无输出结果 结果: 6、现有一个int类型的整数和一个double类型的数进行加法运算,则得到的结果类型为( )   A.int类型   B. double类型   C. float类型   D. long类型 7、以下程序的运行结果为( )    public class Test{ public static void main(String argv[ ]){  System.out.println("x="+5); } } A. 5    B. x=5    C. "x="+5    D. "x="5 8、 以下程序的运行结果为( )    public class Test{ public static void main(String argv[ ]){     System.out.println("good"+"morning"); } } A. goodmorning     B. "good"+"morning"      C. good morning    D. good+morning   9、选择以下程序运行结果( ) 以下代码的输出结果? public class Test{   int x=3;   public static void main(String argv[]){      int x= 012;      System.out.println(x);   } } A.12       B.012    C.10       D.3  10、选择以下程序运行结果( ) public class Exa { public static void main(String[] args) { int var1=10; int var2=20; System.out.println(var1+var2 + " " + var2); } } A. 3021 B.30 21 C. 1020 21 D.30 20 11、请问,以下代码片段错在何处( ) switch(i==10) { case 1: ++i; break; case 2: --i; case 3: i*=5; break; default: i%=3; } A. switch表达式的结果必须是一个整数类型 B.第一个case的选择因子值是一个字符型 C.第二个case的选择因子值是一个字符串型 D.第二个case的选择分支中缺少break语句 三、写出下列程序的运行结果 1、class Variable{ int x=1,y=2,z=3; void init( int x, int y ){ this.x = x; this.y =y; int z=5; System.out.println("**** in init ****"); System.out.println("x = “+x+" y = “+y+" z = "+z); } } public class test1 { public static void main( String[] args) { Variable birth = new Variable(); birth.init(10,20); } } 结果: **** in init **** X = 10 y = 20 z = 5 2、public class SimpleDataType { public static void main (String args [ ] ) { int i = 3; byte bi = (byte)i; short si = 20000; int li=(int)4.25; float f = 3.14f; System.out.println(bi+"\t"+si+"\t"+i+"\t"+li+"\t"+f); boolean b = false; int i1 = 4; b = ( i1!= 0 ); System.out.println("\n"+b); } } 结果: 3 20000 3 4 3.14 true 3、 class A {void callme(){ System.out.println("Inside A's callme() method"); }} class B extends A{ void callme() {System.out.println("Inside B's callme() method"); }} public class Chinese{ public static void main(String [] args) {B a=new B(); a.callme(); }} 结果: Inside B's callme() method 4、public class test { public static void main(String a[]) { System.out.print(7%-2+"\t"); System.out.print(7%2+"\t"); System.out.print(-7%2+"\t"); System.out.println(-7%-2+"\t"); System.out.println("7.2%2.8="+7.2%2.8); } } 结果: 1 1 -1 -1 7.2%2.8=1.6 5、public class A { protected void test(int x,int y) { System.out.println("test(int,int):"+x+" "+y); } protected void test(int x) { System.out.println("test(int):" + x); } protected void test(String str ) { System.out.println("test(String):" + str); } public static void main (String[] args) { A a1 = new A(); a1.test("hello"); a1.test(5,4); }} } 结果: test(String):hello test(int,int):5 4 6、 public class test {         public static void main(String a[]) {            int m=0;            System.out.println("m++="+m++);            System.out.println("++m="+(++m));            boolean x;            x=(5>3)&&(4==6);            System.out.println("x="+x);            m=m%2;            System.out.println("result="+m+1);            int y=m*m+2*m-1;            System.out.println("m="+m+",y="+y);         }      } 结果: m++=0 ++m=2 x=false result=01 m=0,y=-1 6、class Point { int x,y;  public Point(int x1,int y1) {      x=x1;      y=y1; } public static void main(String args[]) {     Point p1=new Point(2,3);      Point p2=new Point(3,5);      Point p3=p1;                 p1.x=18;                    System.out.println(p3.x);       p1=p2;                       System.out.println(p1.x); } } 【运行结果】 18 3   7、public class Test{ int i=1; public static void main(String[] args){ Test x= new Test(); x.thisDemo(3); } void thisDemo(int i){ System.out.println(i); System.out.println(this.i); this.i = i; System.out.println(this.i); } } 【运行结果】 3 1 3 8、class Father{ private String str=“父类实例变量”; static{System.out.println(“父类静态方法”);} public Father(){System.out.println(“父类构造方法”);} { System.out.println(str); } } class Son extends Father{ private String str=“子类实例变量”; { System.out.println(str); } static{System.out.println(“子类静态方法”);} Son(){System.out.println(“子类构造方法”);} public static void main(String[] arge){ new Son(); } } 【运行结果】 父类静态方法 子类静态方法 父类实例变量 父类构造方法 子类实例变量 子类构造方法 9、class parent { int a=3; void f(){a=a+1;} } public class Chinese extends parent { int a=6; Chinese(){ super.f(); a= a+super.a -2; System.out.println("a="+a);} public static void main(String[] args) { Chinese cn=new Chinese(); } } 【运行结果】 a=8 10、Class jj { protected int x = 0; protected void test(int x) { System.out.println("test(int):" + x); } protected void test(String str ) { System.out.println("test(String):" + str); } protected void test(float x) { System.out.println("test(float):" + x ); } protected void test(Object obj) { System.out.println("test(Object):" + obj ); } public static void main (String[] args) { jj a1 = new jj(); a1.test("hello"); a1.test(5); a1.test(6.3); } } 【运行结果】 test(String): hello test(int):5 test(float):6.3 四、编写程序 1 求任意一元二次方程的解,若无实数解,求出虚数解。 public class jhg { public static void main(String[] args) { double a,b,c,d,x1,x2; a = Double.parseDouble(inputLine()); b = Double.parseDouble(inputLine()); c = Double.parseDouble(inputLine()); d = b*b - 4*a*c; if(d >= 0 ) { x1 = (-b + Math.sqrt(d)) / 2*a ; x2 = (-b - Math.sqrt(d)) / 2*a ; System.out.println("x1=" + x1 + " x2=" + x2); } else { double x,y; x=Math.sqrt(-d)/2*a; y=Math.sqrt(-d)/2*a; System.out.println("x1=" + (-b/2*a) + "+" + x + "i"); System.out.println("x2=" + (-b/2*a) + "-" + y + "i"); } } public static String inputLine() { String x=null; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); try { x=br.readLine(); } catch(IOException e) { } return x; } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 考试专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服