Sie sind auf Seite 1von 4

Java Questions

(2)

1. Assume you are designing an application that keeps track of only directors. The
following is a summary of the application. The Person class has been created with the
following attributes: age, name, surname and address. A director will be associated to a
company but can only be a director up to a certain age. Which of the following attributes
are appropriate to include in the Director class?

1. directors name
2. age
3. company name
4. spouse
5. none of the above

2. What would be the output from the following code?

1. public class MyThread implements Runnable {


2. boolean flag = false;
3. public void start() {
4. if (!flag)
5. System.out.println("Hello World");
6. }
7. public static void main(String[] args) {
8. MyThread t = new MyThread();
9. t.start();
10. }
11. }
1. Compilation succeeds, Hello World is printed out.
2. Compilation succeeds, nothing is printed out.
3. Compilation fails.

3. Which constructor will be executed in the code-snippet below?

1. public class PowerSupply


2. {
3. public PowerSupply(String voltage){
4. System.out.println ("PowerSupply(String) executed");
5. }
6. public PowerSupply(Object voltage){
7. System.out.println ("PowerSupply(Object) executed");
8. }
9. public PowerSupply(){
10. System.out.println ("No argument constructor execute");
11. }
12. public static void main(String[] args) {
13. PowerSupply ps = new PowerSupply(null);
14. }
15. }
1. public PowerSupply(String voltage)
2. public PowerSupply(Object voltage)
3. public PowerSupply()
4. Code does not compile, no suitable constructor defined.

4. In an online application you have a code that will be executed when ejbActivate() and
ejbPassivate() are called. The code is used to perform basic house keeping tasks. You
need to know when the code will execute so which of the following statements are true?

Select multiple options:

1. ejbPassivate() is called prior to passivation


2. ejbPassivate() is called immediately after passivation
3. ejbActivate() is called prior to activation
4. ejbActivate() is called immediately after activation

5. What is the difference between Stateful Session beans and Entity beans?

Select multiple options:


1. Stateful Session beans can survive a server crash but Entity beans can’t.
2. Entity beans can survive a server crash but Stateful Session beans can’t.
3. Session beans are typically used to make calls on Entity beans.
4. Entity beans are typically used to make calls on Session beans.

6. SOAP messages must contain just one header element. Select one option:
A. True
B. False

7. What of the following is the most suitable for storing data that must not repeat and
searching is not a priority?

1. List
2. Map
3. Vector
4. ArrayList
5. Set
6. HashMap

8. What is the purpose of a layout manager?


A. to manage the interaction of JavaBeans
B. to provide an area to display AWT components
C. to display information about the coordinates of components in an
applet
to control the arrangement of components within the display area of
a container
9. Which type of join is used in this query?

SELECT last_name “Name”, hire_date “Hire Date, loc “Location”


FROM employee, department
WHERE employee.deptno = department.deptno

A. Outer join
B. Self join
C. Equijoin
D. Non-equijoin

10. Given the following code what will be the output?

class ValHold{
public int i = 10;
}
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);

}//End of amethod

public void another(ValHold v, int i){


i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another
}

1) 10,0,30
2) 20,0,30
3) 20,99,30
4) 10,0,20
Answers (2)

1. Answer 3 is correct.
The company name is the only attribute that is appropriate to include in the Director
class. The name and the age of the director can be stored in the Person class. The spouse
was not a requirement; if this was a requirement then it would be appropriate to change
the design of the Person class to include this.

2. Answer 3 is correct.
The compilation fails because the run() method that is defined by the Runnable interface
is not implemented.

3. Answer 1 is the correct answer because when both the String and Object argument
constructors are considered by the compiler for eligibility, the compiler will choose the
'Most specific method' - which in this case is the String version.

The most specific method is defined as the method which can on invocation,
call the other method without a compile time error. Therefore since the String version can
in turn call the Object version but not the other way round, the String version is used.

4. Choices 1 and 4 are correct.


1. ejbPassivate() is called prior to passivation
4. ejbActivate() is called immediately after activation

5. Choices 2 and 4 are correct


2. Entity beans can survive a server crash but Stateful Session beans can’t.
4. Entity beans are typically used to make calls on Session beans.

6. Choice B (false} is corect

7. Choice 5 (Set)

8. Choice D (To control the arrangement of components within the display area of a
container )

9. Choice C (Equijoin)

10. Choice 4) 10,0,20


In the call
another(v,i);
a reference to v is passed and thus any changes will be intact after this call.

Das könnte Ihnen auch gefallen