高手!!!来做几道Java题吧!!!!
1.Java Core
Question 1
The following code represents 2 classes A and B in the same package P. Is the code correct at compilation time ?Explain why ?
Code:
package P ;
public class A{
String name;
public A(String name){
this.name = name;
}
}
package P ;
public class B extends A{
int age;
public B(String aName, int anAge){
name = aName;
age = anAge;
}
}
Question 2
The following code represents 2 classes A and B in the sam package P.Is the code correct at compilation time?Explain why?
package P;
public class A{
protected int age;
}
package P;
public class B{
public void method(){
A a = new A();
a.age = 0;
}
}
Question 3
What is the output of the following code?Explain why?
public class A{
public static void main(String args){
System.out.println("hello" == "hello");
System.out.println("hello" == new String("hello"));
}
}
Question 4
What is the output of the following code ?Explain why?
public class A{
public static void main (Striing[] args){
String aValue = null;
methodTwo(aValue);
System.out.pringln(aValue);
}
protected static void methodTwo (String value){
value = "hell";
}
}
Question 5
The following code represents 2 classes A and B in the same package P. Furthermore B is an Inner class of A.
Is the code correct at compilation time?Explain why?
public class A{
int age;
class B{
public void method(){
if (age<0){
System.out.println("Bad Value");
}
}
}
}
Question 6
Explain the difference between accessing a file in the classpath of your application and a file in the working driectory of
your application.Especially if the working directory is not in the classpath. To load a properties file or an image for instance.
Question 7
Given a class"com.foo.Bar" with a default constructor.How can you instantiate an instance of this class just with its name
as a String.(do not use the "new" keyword)
Given an example from one of the standard java libraries where this mechanism is used.
Question 8
Given the class A.Provide the code of the method public boolean equals(Object obj)
which will ensure that 2 instance of A are equals if and only if they the same name;
public class A {
String name;
public A(String name){
this.name = name;
}
}
Question 9
What is the main difference between the handling of Exception classes that inherits(directly of not)
from java.lang.RuntimeException and the others.
2. Good Pratice and Design Patterns
Question 15
Java does not provide equivalency of C enum.Give the code of a class which will implements the equivalence of the following enum;
!!!C code
Typedef enum (MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY) DaysOfWeek;
Question 16
Explain briefly the concept of the Singleton pattern.Give a sample of class CarFactory
which will use this pattern;
3.Servlet questions
Question 17
Describe the life cycle of a servlet instance.
Question 18
When a servlet is invoked through a HTML form,how does if retrieve the values of the form parameters?How does it retrieve multiple values
if a form entry provides such a possibility?
Question 19
Given a servlet class,how do you make if available as a web resource in a web application?Give a basic sample.
Question 20
Your servlet needs to be configured before its first invocation.For instance ,it needs the path to particular file one the deployment
system. The value of this path must be configurable at deployment time.What mechanism would you use?
4.JSP questions
Question 21
Why do JSPs have a reputation of having a long response time at their first invocation?Is there a way to prevent this behavior?
Question 22
Give a list of the mostly used implicit objects that accessible by a JSP(up to9).
5.WebApplication
Question 23
Give the organization (folder hierarchy) of a standard web appliction containing servlets.JSPs,tagLibs,images,html pages and a jar dependency.
Question 24
What is the new mechanism introduced in the 2.3 version of the servlet ,which gives the possibility for a web application to be
notified at its initialization?
What are the steps that you need to implement to use this mechanism?
What other kinds of notification are available?
Question 25
In a basic standard web appliction (comprised of servlets and JSPs,with no additional packages like Struts),how would you ensure
that each html error 404 is redirected to a particular HTML page?
问题点数:0、回复次数:3Top
1 楼huanghhh4(hews)回复于 2005-11-04 17:23:24 得分 0
1.可以通过。
2。不能通过。因为访问不了protected int age;这个方法。
3。public static void main(String args)如果这里没有少[]得话。答案是ture ,false
4。答案是null 如果public static void main (Striing[] args)这里得i不是多一个得话。
5。可以通过编译
Top
2 楼ryhome()回复于 2005-11-04 20:10:25 得分 0
huanghhh4(hews)
--------------------------------------------------------------------------------
不只是要答案 explain why是重点Top
3 楼firefly83()回复于 2005-11-05 10:58:47 得分 0
1:不可以。应改为:
package P;
public class B extends A{
int age;
public B(int age,String value){
super(value);
age=age;
}
} cause:如果要给name赋值必须调用A类的构造函数,name不可以由B类直接使用。
2:不可以。因为B没有继承A所以访问不了他的protected成员
3:true,false.第1次输出是判断后输出(2个都为字符串)。第2次判断第一个是字符串,第二个是对象。不知道这么说对不对。
4:答案是null,不光象楼上说的那样 还要主要 println不可以写成pringln。
cause:value="hello" 正好点中了那句名言“对象是按引用传递的,但对象本身是按值传递的”.
5:可以通过。cause:内部类可以直接访问外部类的成员。Top




