




已阅读5页,还剩26页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JAVA 笔试题精华版 public class Test2 public static void main String args Float a new Float 3 4 System out println a SIZE a new Float 34000 System out println a SIZE 让我们来看看此程序会输出什么呢 我们先来看看 JDK 的解释吧 public static final int SIZE The number of bits used to represent a float value 意思是说 通常去描述一个 float 值的位数 这个是一个常量 来看看源码吧 public static final int SIZE 32 final int 变量一旦被定义就不能被改变 1 写出下面代码的结果 public class TestString public static void link String a a World public static void main String args String a Hello link a System out println a 答 这道题考两个方面 1 String 对象的内容是不能改变的 a World 并不是把 a 所指对象改变 而是先生成一个临时 String 对象 其值为 a World 然后在把这个临时 对象赋给 a 2 Java 中函数参数传递方式为 Call by value link 方法中会生产 a 的一个 拷贝 同样指向 a 所指的对象 综合以上两点 得出结果为 Hello 2 写出下面代码的结果 System out println ja va java 答 用来比较对象的引用 而 equals 用来比较对象的内容 但是如果是字符串常量 用 也可以比较内容 是否相等 ja va 和 java 都是字符串常量 因此结果为 true 同理 下面代码结果也是 true final String str java System out println str java 1 选出用法错误的 a Stirng a Gone With Wind String t Wind String m m a t B Stirng a Gone With Wind String m m a 3 one C Stirng a Gone With Wind Sting m m a toUpperCase D 不记得了 选 AB 2 选出能正确赋值的 public class A private int a public void change int m return m public class B extends A public int b public static void main A aa new A B bb new B int k px 在 px 处可以正确赋值的有 A k m B k b C k aa a D k bb change 30 E k bb a 选 C 3 此程序会输出什么 package com class A public A a1 public void a1 System out println A a1 public class B extends A int bb 0 public B bb 1000 public void a1 System out println bb is bb System out println B a1 public static void main String args new B 答案 bb is 0 B a1 看看执行顺序就明白了 package com class A 3 public A a1 public void a1 System out println A a1 public class B extends A int bb 0 2 public B 5 bb 1000 4 public void a1 System out println bb is bb System out println B a1 public static void main String args 1 new B 在方法被 a1 被重写的情况下 父类的 a1 是没有机会 被调用的 posted on 2007 12 15 10 43 上善若水 阅读 235 评论 3 编辑 收藏所属分类 Java 笔 试与面试 Comments re JAVA 笔试题 金山软件 未登录 lovejava 比较喜欢面试题 Posted 2007 12 16 11 21 回复 更多评论 re JAVA 笔试题 金山软件 未登录 古风 public class A public int a public int change int m return m public A System out println constructA a1 public void a1 System out println A a1 public class B extends A int bb 0 public B System out println constructB bb 1000 System out println bb bb public void a1 System out println bb is bb System out println B a1 public static void main String args new B 执行结果 constructA bb is 0 B a1 constructB bb 1000 public class Test public static void changeStr String str str welcome public static void main String args String str 1234 changeStr str System out println str 此题结果为 1234 比较简单分析下内存就行了 2 public class ForTest static boolean foo char c System out println c return true public static void main String args int i 0 for foo A foo B foo C i foo D 此题结果为 ABDCBDCB 这道题考查的 for 循环的执行顺序 for int i 0 i 10 i 首先先执行 int i 0 注意这个只是初始化一次 就是在第一次的时候 接着执行 i 10 然后执行方法体 里面的内容 最后才执行 i 第二次及以后就直接执行 i 10 然后方法体 最后 i 如此顺序直到结束为止 3 1 class A 2 protected int method1 int a int b return 0 3 Which two are valid in a class that extends class A Choose two A public int method1 int a int b return 0 B private int method1 int a int b return 0 C private int method1 int a long b return 0 D public short method1 int a int b return 0 E static protected int method1 int a int b return 0 此题考查的是继承重写问题 当一个子类重写父类的方法时 重写的方法的访问权限 必须大于等于父类的访问权限 在此题中父类中的方法访问权限为 protected 子类只能是 protected 或 public 这时 是符合题意的 由于选项 的形参和父类的不一样 没有重写的效果 所以 在子类出现也是没问题的 所以此题选 AC 1 public class Outer 2 public void someOuterMethod 3 Line 3 4 5 public class Inner 6 public static void main String argv 7 Outer o new Outer 8 Line 8 9 10 Which instantiates an instance of Inner A new Inner At line 3 B new Inner At line 8 C new o Inner At line 8 D new Outer Inner At line 8 new Outer new Inner 此题选 A 内部类的实例化可以在普通方法里也可以在 static 方法里实例化 如下 package com test a public class Outer Inner i new Outer Inner public void method new Inner public class Inner public static void main String args Outer o new Outer Inner i o new Inner static void a Outer o new Outer Inner i o new Inner public class Jtest int m 1 int i 3 void Jtest m 2 i 4 public static void main String args Jtest app new Jtest System out println app m app i 写出输出 结果是 1 3 因为在这里 void Jtest 并没有并调用 它只是一个 方法 而非构造方法 这样的编写是有警告的 不过 可以运行 public class Jtest int m 1 int i 3 Jtest m 2 i 4 public static void main String args Jtest app new Jtest System out println app m app i 写出输出 结果是 2 4 调用了构造方法 不加修饰符 默认访问权限是 package access 在 Java 里没有关键字表示 就是 包内的能访问 包外就不行了 即使导入也不行 public class Test static void oper int b b b 100 public static void main String args int a 99 oper a System out println a 输出为 99 我们来分析一下内存 int a 99 首先在栈里面开辟一块空间保存 a 比如 a xxxx 然后调用 oper a 这时把 a 的值 99 赋给 int b b 在内存里也开辟了自己的空间 此时 值也是 99 然后执行 oper a 方法体 b b 100 此时 b 的值为 199 a 的值为 99 public class Test public static void main String args String a new String A String b new String B oper a b System out print a b static void oper String c String d c concat B d c 此程序输出 A 和 B 原因就是 String 是 final 类型的 并不会被改变 public class Test public static void main String args String a new String A String b new String B a concat aa System out println a b 这个还是会输出 A B 原因同上 package intervie public class Test public static void main String args String a new String A String b new String B a a concat aa System out println a b 做了下改动 再来看看 结果就不同了 输出的是 Aaa B 因为 String 是 final 类型的 所以执行到 a c concat aa 会在 heap 里新创建一个对象 而 a 指向它 这是一新的地址 同 String a 这个已经不同了 所以输出的是后一个 即改变后的值 public class Test static void oper StringBuffer c StringBuffer d d c append B public static void main String args StringBuffer a new StringBuffer A StringBuffer b new StringBuffer B oper a b System out println a b 此程序会输出 AB B package org public class Test public static void main String args A a new B a print class A private int i 1 public A int i 2 public void print System out println The result is i class B extends A private int i 3 public B int i 6 public void print System out println The result is i 输出结果是 3 此题考查的是多态 在这里是父类的引用指向子类的对象 父
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版进出口合同模板:外贸合同示范文本
- 2025年咖啡师职业技能测试卷:咖啡师咖啡店创业试题
- 政府采购评审专家考试试题库判断题及答案
- 2025年育婴师职业技能大赛模拟试卷:育婴师职业素养与心理健康试题解析
- 2025年护士执业资格考试题库-内科护理学专项护理营养学专项试题
- 不锈钢消防管道安装施工方案详稿
- 2025年营养师基础知识考核试卷:营养师职业素养试题
- 2025年美容师初级技能水平测试卷:美容师美容院经营管理与客户服务试题型
- 2025国际商事合同翻译服务条款
- 宴会认知说课稿中职专业课-餐饮服务与管理-旅游类-旅游大类
- TSCS 000013-2021 碳化硼-碳化硅芯块 无机阴离子(F-、Cl-、Br-、I-)的测定 离子色谱法
- GB/T 6426-1999铁电陶瓷材料电滞回线的准静态测试方法
- GB/T 14846-2014铝及铝合金挤压型材尺寸偏差
- 广西版建筑装饰装修工程消耗量定额说明及计算规则
- GA/T 594-2006保安服务操作规程与质量控制
- 髋关节解剖资料课件
- 坚持男女平等基本国策(妇联培训)课件
- 颅脑外伤(共61张PPT)
- 人教版《生命.生态.安全》六年级上册全册教案
- 矿种代码与规模分类表
- 2022版义务教育语文课程标准解读之核心素养与课程目标PPT
评论
0/150
提交评论