Answers# 101-120

Answer 101)

2) If multiple listeners are added to a component the events will be processed for all but with no guarantee in the order
4) You may remove as well add listeners to a component.

It ought to be fairly intuitive that a component ought to be able to have multiple listeners. After all, a text field might want to respond to both the mouse and keyboard


Answer 102)

1) b=m;
3) d =i;

You can assign up the inheritance tree from a child to a parent but not the other way without an explicit casting. A boolean can only ever be assigned a boolean value.


Answer 102)

2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a method declared with the keyword synchronized
4) Thread scheduling algorithms are platform dependent

Yes that says dependent and not independent.


Answer 103)

2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type

This question is about the requirement to understand the difference between the "is-a" and the "has-a" relationship. Where a class is inherited you have to ask if it represents the "is-a" relationship. As the difference between the root and the two children are the operating system you need to ask are Linux and Windows types of computers.The answer is no, they are both types of Operating Systems. So option two represents the best of the options. You might consider having operating system as an interface instead but that is another story.

Of course there are as many ways to design an object hierarchy as ways to pronounce Bjarne Strousjoup, but this is the sort of answer that Sun will proabably be looking for in the exam. Questions have been asked in discussion forums if this type of question really comes up in the exam. I think this is because some other mock exams do not contain any questions like this. I assure you that this type of question can come up in the exam. These types of question are testing your understanding of the difference between the is-a and has-a relationship in class design.


Answer 104)

1) An inner class may be defined as static
4) An inner class may extend another class

A static inner class is also sometimes known as a top level nested class. There is some debate if such a class should be called an inner class. I tend to think it should be on the basis that it is created inside the opening braces of another class. How could an anonymous class have a constructor?. Remember a constructor is a method with no return type and the same name as the class. Inner classes may be defined as private


Answer 105)

4) Compilation and output of "Not equal! 10"

The output will be "Not equal 10".  This illustrates that the Output +=10 calculation was never performed because processing stopped after the first operand was evaluated to be false. If you change the value of b1 to true processing occurs as you would expect and the output is "We are equal 20";.


Answer 106)

2)j= i<<j;

4)j=i<<l;


Answer 107)

4) 12

As well as the binary OR objective this questions requires you to understand the octal notaction which means that the leading letter zero (not the letter O)) means that the first 1 indicates the number contains one eight and nothing else. Thus this calculation in decimal mean

8|4

To convert this to binary means

1000

0100

----

1100

----

Which is 12 in decimal

The | bitwise operator means that for each position where there is a 1, results in a 1 in the same position in the answer.



Answer 108)

2)s+=i;

Only a String acts as if the + operator were overloaded


Answer 109)

Although the objectives do not specifically mention the need to understand the I/O Classes, feedback from people who have taken the exam indicate that you will get questions on this topic. As you will probably need to know this in the real world of Java programming, get familiar with the basics. I have assigned these questions to Objective 10.1 as that is a fairly vague objective.

1) File f = new File("/","autoexec.bat");
2) DataInputStream d = new DataInputStream(System.in);
3) OutputStreamWriter o = new OutputStreamWriter(System.out);

Option 4, with the RandomAccess file will not compile because the constructor must also be passed a mode parameter which must be either "r" or "rw"


Answer 110)

1)o1=o2;

2)b=ob;

4)o1=b; 


Answer 111)

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.


Answer 112)

1) public void amethod(String s, int i){}
4) public void Amethod(int i, String s) {}

Overloaded methods are differentiated only on the number, type and order of parameters, not on the return type of the method or the names of the parameters.


Answer 113)


4)Base b = new Base(10);

Any call to this or super must be the first line in a constructor. As the method already has a call to this, no more can be inserted.



Answer 114)

1)System.out.println(s);
4) System.out.println(iArgs);

A class within a method can only see final variables of the enclosing method. However it the normal visibility rules apply for variables outside the enclosing method.


Answer 115)

1) yield()
2) sleep
4) stop()

Note, the methods stop and suspend have been deprecated with the Java2 release, and you may get questions on the exam that expect you to know this. Check out the Java2 Docs for an explanation


Answer 116)

1) addElement


Answer 117)

The import statement allows you to use a class directly instead of fully qualifying it with the full package name, adding more classess with the import statement does not cause a runtime performance overhad. I assure you this is true. An inner class can be defined with the private modifier.

3) An inner class can be defined with the protected modifier
4) An interface cannot be instantiated


Answer 118)

1) mousePressed(MouseEvent e){}
4) componentAdded(ContainerEvent e){}


Answer 119)

1) iterator
2) isEmpty
3) toArray


Answer 120)

2) 2) Ensures only one thread at a time may access a method or object


Answers# 81-100   Questions# 101-120   Answers# 121-140           Index Home