logo资料库

华为综合面试题集及感受.doc

第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
资料共14页,剩余部分请下载后查看
QUESTION NO: 1 1、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); } } Please write the output result : QUESTION NO:2 1. public class Test { 2. static boolean foo(char c) { 3. System.out.print(c); 4. return true; 5. } 6. public static void main( String[] argv ) { 7. int i =0; 8. for ( foo('A'); foo('B')&&(i<2); foo('C')){ 9. i++ ; 10. foo('D'); 12. } 13. } 14. } What is the result? A. ABDCBDCB B. ABCDABCD C. Compilation fails. D. An exception is thrown at runtime. QUESTION NO: 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; }
QUESTION NO: 4 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() QUESTION NO: 5 Which method is used by a servlet to place its session ID in a URL that is written to the servlet’s response output stream? A. The encodeURL method of the HttpServletRequest interface. B. The encodeURL method of the HttpServletResponse interface. C. The rewriteURL method of the HttpServletRequest interface. D. The rewriteURL method of the HttpServletResponse interface. QUESTION NO: 6 Which two are equivalent? (Choose two) A. <%= YoshiBean.size%> B. <%= YoshiBean.getSize()%> C. <%= YoshiBean.getProperty("size")%> D. E. F. G. QUESTION NO: 7 Which of the following statements regarding the lifecycle of a session bean are correct? 1. java.lang.IllegalStateException is thrown if SessionContext.getEJBObject() is invoked when a stateful session bean instance is passivated. 2. SessionContext.getRollbackOnly() does not throw an exception when a session bean with bean-managed transaction demarcation is activated. 3. An exception is not thrown when SessionContext.getUserTransaction() is called in the afterBegin method of a bean with container-managed transactions. 4. JNDI access to java:comp/env is permitted in all the SessionSynchronization methods of a
stateful session bean with container-managed transaction demarcation. 5. Accessing resource managers in the SessionSynchronization.afterBegin method of a stateful session bean with bean-managed transaction does not throw an exception. 第二部分:概念题 1. 描述 Struts 体系结构?对应各个部分的开发工作主要包括哪些? 2. XML 包括哪些解释技术,区别是什么? 3. JSP 有哪些内置对象和动作?它们的作用分别是什么? 4、SQL 问答题 SELECT * FROM TABLE
和 SELECT * FROM TABLE WHERE NAME LIKE '%%' AND ADDR LIKE '%%' AND (1_ADDR LIKE '%%' OR 2_ADDR LIKE '%%' OR 3_ADDR LIKE '%%' OR 4_ADDR LIKE '%%' ) 的检索结果为何不同? 5、SQL 问答题 表结构: 1、 表名:g_cardapply 字段(字段名/类型/长度): g_applyno varchar 8;//申请单号(关键字) g_applydate bigint 8;//申请日期 g_state varchar 2;//申请状态 2、 表名:g_cardapplydetail 字段(字段名/类型/长度): g_applyno varchar 8;//申请单号(关键字) g_name varchar 30;//申请人姓名 g_idcard varchar 18;//申请人身份证号 g_state varchar 2;//申请状态 其中,两个表的关联字段为申请单号。 题目: 1、 查询身份证号码为 440401430103082 的申请日期 2、 查询同一个身份证号码有两条以上记录的身份证号码及记录个数 3、 将身份证号码为 440401430103082 的记录在两个表中的申请状态均改为 07 4、 删除 g_cardapplydetail 表中所有姓李的记录 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); } }
这一题我想他主要考查 static 这个关键字,changestr 是个静态的方法(类方法)那么 str 应 该也是一个静态成员,所有的对象都是公用这样的一个成员,那么对他的修改应该是可以保 持的。而为什么最后的结果却是初始值 1234,我有点迷惑 终于明白了:按值传递意味着当将一个参数传递给一个函数时,函数接收的是原始值的一个 副本。因此,如果函数修改了该参数,仅改变副本,而原始值保持不变。按引用传递意味着 当将一个参数传递给一个函数时,函数接收的是原始值的内存地址,而不是值的副本。因此, 如果函数修改了该参数,调用代码中的原始值也随之改变。 不管是在 c/c++中还是在 java 函数调用都是传值调用,. 当参数是对象的时候,传递的是对象的引用,这个和 c/c++传递指针是一个道理,在函数中 改变引用本身,不会改变引用所指向的对象,而在 QUESTION NO: 1 中只是改变了引用,所 以在 main 函数中输出还是原来的那个值:1234 参数是对象时传的是地址。但 str="welcome";相当于 str=new String("welcome");,所以原对象 没变。 可以参考以下代码: public class Test { public int ss = 999; public Test(int s){ ss = s; } public static void changeStr(Test t){ t.ss = 888; } public static void main(String[] args) { Test t = new Test(999); changeStr(t);
System.out.println(t.ss); } } public class Test { public int ss = 999; public Test(int s){ ss = s; } public static void changeStr(Test t){ t = new Test(888); } public static void main(String[] args) { Test t = new Test(999); changeStr(t); System.out.println(t.ss); } } QUESTION NO:2 1. public class Test { 2. static boolean foo(char c) { 3. System.out.print(c); 4. return true; 5. } 6. public static void main( String[] argv ) { 7. int i =0; 8. for ( foo('A'); foo('B')&&(i<2); foo('C')){ 9. i++ ; 10. foo('D'); 12. } 13. } 14. } What is the result? A. ABDCBDCB B. ABCDABCD C. Compilation fails.
D. An exception is thrown at runtime 做一下这个吧!! 第一题终于清楚了。 对象是传引用的。但是下面还是有区别 public class test6 { public int ss = 999; public test6(int s){ ss = s; } public static void changeStr(test6 t){ t.ss = 888; } public static void change(test6 t){ t = new test6(222); } public static void main(String[] args) { test6 t = new test6(999); changeStr(t); System.out.println(t.ss); change(t); System.out.println(t.ss); } }
import javax.swing.JOptionPane; public class Test { public void changeStr(String str){ str="welcome"; } public void main(String[] args) { String str="1234"; str="welcome"; //changeStr(str); JOptionPane.showMessageDialog(null,str); } } 如果这样做的话结果是 welcome 在我我想说的是在 C 语言以后所有的参数传递都是值传递,问题是传的值是是什么,而没有 什么引用传递之类的东西。 关于输出为 1234 而不是 welcome 还有待进一步分析。 我现在去上课了,回来再和大家细说 对第一题的详细分析: Java 中函数参数传递是值传递,在 C 语言以后的都是这样的,关键是传进来的值是什么(这 一点我在上面说了到一次)。 ①如果参数是基础类型,如 int 型的,则传进来的是 int 型变量的值,这个值放在堆里。 举个例子: void fun(int i){}; int i = 5; fun(i); 传进 fun 函数的是 5; ②如果参数是引用类型。如 String 型的,则传进来的是 String 型变量的值,这个值放在栈里, 此值是该变量将要指向的对象的地址。 举个例子: void fun(String str0){}; String str = "Hello"; fun(str);
分享到:
收藏