`
sakakokiya
  • 浏览: 488543 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Java笔试题一套 需要的朋友可以看看

阅读更多
2.下面代码的输出是什么?一共在内存中生成了几个String对象?为什么?
String s1 = “aaa”;
String s2 = “aaa”;
String s3 = new String(“aaa”);
String s4 = new String(“AAA”);
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s1.equals(s3));
3.下列程序在1处是否会有异常,如果没有,输出是什么?是否会运行到2处,如果会,输出是什么?为什么会有这样的结果?
public class TestClass {
public void test1() {
List list = new ArrayList();
test2(list);
System.out.println(list.size()); // 1处
test3(list);
System.out.println(list.size()); // 2处
}
public void test2(List list) {
list = null;
}
public void test3(List list) {
list.add(“aaaa”);
}
}
4.请选出下面哪些描述是正确的。
public class ClassA {
public synchronized void a(){
}
public synchronized void b(){
}
}
2 instances of ClassA had been instantiated obj1 and obj2.
Which statements about thread are true?
1)One thread is calling obj1.a(), another thread can call obj1.b().  .
2)One thread is calling obj1.a(), another thread cannot call obj1.b(). 
3)One thread is calling obj1.a(), another thread can call obj2.b().  .
4)One thread is calling obj1.a(), another thread cannot call obj2.b(). 
5.下面的程序输出是什么?为什么?
public class Parent {
public void test(ArrayList list) {
System.out.println(”invoke parent's test method”);
}
public static void main(String[] args) {
Child a = new Child();
ArrayList list = new ArrayList();
a.test(list);
}
}
class Child extends Parent {
public void test(List list) {
System.out.println(”invoke child's test method”);
}
}
6.下面的程序输出是什么?为什么?
public class Parent {
public void test(List list) {
System.out.println(”invoke parent's test method”);
}
public static void main(String[] args) {
Child a = new Child();
ArrayList list = new ArrayList();
a.test(list);
}
}
class Child extends Parent {
public void test(List list) {
System.out.println(”invoke child's test method”);
}
}
7.仔细分析下面的程序,写出程序的输出结果。
public class Parent {
{
System.out.println(”parent instance block”);
}
public void test() {
System.out.println(”parent test method”);
}
static {
System.out.println(”parent static block”);
}
public Parent() {
System.out.println(”parent constructor”);
test();
}
public static void main(String[] args) {
new Child();
}
}
class Child extends Parent {
private static int staticValue = 20;
private int instanceValue = 20;
{
System.out.println(”child instance block”);
}
public void test() {
System.out.println(”child test method”);
System.out.println(”static value is: ” + staticValue);
System.out.println(”instance value is: ” + instanceValue);
}
static {
System.out.println(”child static block”);
}
public Child() {
System.out.println(”child constructor”);
}
}
8.下面程序的输出是什么?
public class TestException {
public void test1() {
int result = test2();
System.out.println(result);
}
public int test2() {
try{
String s = null;
s.substring(0, 1);
return 1;
} catch(Exception e) {
return 2;
} finally {
return 3;
}
}
public static void main(String[] args) {
(new TestException()).test1();
}
}
9.请写出数据库查询操作的伪代码,程序不需要通过编译,只要思路正确,关键步骤不丢失就可以了。注意异常的捕获,IO流的关闭。可能用到的类或接口有(Connection,DriverManager, Statement, PreparedStatement, ResultSet, SQLException)。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics