华为公司面试题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
华为公司 java 面试题
第一部分:选择题
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);
}
}
Please write the output result :welcome
QUESTION NO:2
1. public class Test {
2. static boolean foo(char c) {
3.
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
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) b
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 d
1. public class Outer{
2. public void someOuterMethod() {
3. }
5. public class Inner{}
6. public static void main( String[]argv ) {
7. Outer o = new Outer();
8. }
10. }
Which instantiates an instance of Inner?
A. new Inner(); new Inner(); 8
new (); new (); ew Inner()
QUESTION NO: 5
Which method is used by a servlet to place its session ID in a URL th at is written to the servlet’s response output stream? d
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. <%= %>
B. <%= ()%>
C. <%= ('size')%>
D.
E.
F.
G.
QUESTION NO: 7
Which of the following statements regarding the lifecycle of a sessio n bean are correct?
1. is thrown if () is invoked when a stateful session bean instanc
e is passivated.
2. () does not throw an exception when a session bean with bean-man aged transaction demarcation is activated.
3. An exception is not thrown when () is called in the afterBegin m ethod of a bean with container-managed transactions.
4. JNDI access to java:comp/env is permitted in all the SessionSync hronization methods of a stateful session bean with container-managed