广博吧

位置:首页 > 学习经验 > 考研

长虹集团笔试题目

考研1.24W

有关于长虹集团笔试题目,请使用应届毕业生笔试频道

长虹集团笔试题目

   1、两个对象值相同(ls(y) == true),但却可有不同的hash code,这句话对不对?

不对,有相同的hash code。

 

2、当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递?

是值传递。java 编程语言只由值传递参数。当一个对象实例作为一个参数被传递到方法中时,参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变,但对象的引用是永远不会改变的。

 

3、swtich是否能作用在byte上,是否能作用在long上,是否能作用在string上?

switch(expr1)中,expr1是一个整数表达式。因此传递给 switch 和 case 语句的参数应该是 int、 short、 char 或者 byte。long,string 都不能作用于swtich。

 

4、写一个singleton出来。

singleton模式主要作用是保证在java应用程序中,一个类class只有一个实例存在。

一般singleton模式通常有几种种形式:

第一种形式:定义一个类,它的构造函数为private的',它有一个static的private的该类变量,在类初始化时实例话,通过一个public的getinstance方法获取对它的引用,继而调用其中的方法。

public class singleton {private singleton(){}private static singleton instance = new singleton();public static singleton getinstance() {return instance;}}

第二种形式:

public class singleton {private static singleton instance = null;public static synchronized singleton getinstance() {if (instance==null)instance=new singleton();return instance; }}