📄 scjp试题-scjpmockexam3.txt
字号:
3) A Frame with one large button marked Four in the Centre
The default layout manager for a Frame is the BorderLayout manager. This
Layout manager defaults to placing components in the centre if no constraint is
passed with the call to the add method.
--------------------------------------------------------------------------------
Answer 13)
Objective 8.2)
4) Do nothing, the FlowLayout will position the component
--------------------------------------------------------------------------------
Answer 14)
Objective 8.2)
1) Use the setLayout method
Answer 15)
Objective 8.2)
1) ipadx2) fill3) insets
--------------------------------------------------------------------------------
Answer 16)
Objective 8.2)
2) The buttons will run from left to right along the top of the
frameThe call to the setLayout(new FlowLayout()) resets the Layout
manager for the entire frame and so the buttons end up at the top rather than
the bottom.
--------------------------------------------------------------------------------
Answer 17)
Objective 8.2)
2) It is a field of the GridBagConstraints class for controlling component
placement3) A valid settting for the anchor field is
GridBagconstraints.NORTH
--------------------------------------------------------------------------------
Answer 18)
Objective 7.1)
4) Clean compile but no output at runtime
This is a bit of a sneaky one as I have swapped around the names of the
methods you need to define and call when running a thread. If the for loop were
defined in a method calledpublic void run()
and the call in the main method had been to b.start()
The list of values from 0 to 9 would have been
output.
--------------------------------------------------------------------------------
Answer 19)
Objective 8.2)
2) falseYou can re-use the same instance of the GridBagConstraints
when added successive components.
--------------------------------------------------------------------------------
Answer 20)
Objective 10.1)
4) An interface that ensures that implementing classes cannot contain
duplicates
--------------------------------------------------------------------------------
Answer 21)
Objective 10.1)
2) The add method returns false if you attempt to add an element with
a duplicate value
I find it a surprise that you do not get an
exception.
--------------------------------------------------------------------------------
Answer 22)
Objective 7.1)
1) The program exits via a call to exit(0);2) The priority of another
thread is increased3) A call to the stop method of the Thread class
Java threads are somewhat platform dependent and you should be carefull
when making assumptions about Thread priorities. On some platforms you may find
that a Thread with higher priorities gets to "hog" the processor. You can read
up on this in more detail at http://java.sun.com/docs/books/tutorial/essential/threads/priority.html
--------------------------------------------------------------------------------
Answer 23)
Objective 4.1)
4) The class can only access final variables
--------------------------------------------------------------------------------
Answer 24)
Objective 7.1)
1) To call from the currently running thread to allow another thread of
the same or higher priority to run
Option 3 looks plausible but there is no guarantee
that the thread that grabs the cpu time will be of a higher priority. It will
depend on the threading algorithm of the Java Virtual Machine and the underlying
operating system
--------------------------------------------------------------------------------
Answer 25)
Objective 6.2)
4) Compilation and running with output 0 to 9
--------------------------------------------------------------------------------
Answer 26)
Objective 2.1)
1) None of these optionsBecause of the
lack of a break statement after the break 10; statement the actual output will
be "ten" followed by "twenty"
--------------------------------------------------------------------------------
Answer 27)
Objective 3.1)
4) System.gc();
--------------------------------------------------------------------------------
Answer 28)
Objective 4.4)
1) Compilation succeeds and at run time an output of 0 and falseThe
default value for a boolean declared at class level is false, and integer is
0;
--------------------------------------------------------------------------------
Answer 29)
Objective 1.2)
1) Compile time error
You will get an error saying something like "Cant make a static reference to
a non static variable". Note that the main method is static. Even if main was
not static the array argv is local to the main method and would thus not be
visible within amethod.
--------------------------------------------------------------------------------
Answer 30)
Objective 5.2)
3) Output of "Not equal"
Despite the actual character strings matching, using the == operator will
simply compare memory location. Because the one string was created with the new
operator it will be in a different location in memory to the other string.
--------------------------------------------------------------------------------
Answer 31)
Objective 2.3)
4) Compile and run with output of "Pausing" and "Continuing" after a key is
hit
An overriden method in a sub class must not throw Exceptions not thrown in
the base class. In the case of the method amethod it throws no exceptions and
will thus compile without complain. There is no reason that a constructor cannot
be protected.
--------------------------------------------------------------------------------
Answer 32)
Objective 6.3)
4) Compile time error because of the line creating the instance of Inner
This looks like a question about inner classes but it is also a reference
to the fact that the main method is static and thus you cannot directly access a
non static method. The line causing the error could be fixed by changing it to
say Inner i = new Outer().new Inner();
Then the code would compile and run producing the output "Inner"
--------------------------------------------------------------------------------
Answer 33)
Objective 4.6)
1) Error at compile time
If you implement an interface you must create bodies for all methods in that
interface. This code will produce an error saying that MyWc must be declared
abstract because it does not define all of the methods in WindowListener. Option
4 is nonsense as comments can appear anywhere. Option 3 suggesting that it might
compile but not produce output is ment to mislead on the basis that what looks
like a constructor is actually an ordinary method as it has a return type.
--------------------------------------------------------------------------------
Answer 34)
Objective 1.2)
4) Compile time error
An error will be caused by attempting to define an integer as static within a
method. The lifetime of a field within a method is the duration of the running
of the method. A static field exists once only for the class. An approach like
this does work with Visual Basic.
Answer 35)
Objective 9.5)
4)int z = 015;
The letters c and s do not exist as literal indicators and a String must be
enclosed with double quotes, not single as in this case.
--------------------------------------------------------------------------------
Answer 36)
Objective 4.3)
1)double4)instanceofNote the upper case S on switch means it is
not a keyword and the word then is part of Visual Basic but not Java. Also,
instanceof looks like a method but is actually a keyword,
--------------------------------------------------------------------------------
Answer 37)
Objective 9.2)
4) -3.0
--------------------------------------------------------------------------------
Answer 38)
Objective 4.2)
3) one
Command line parameters start from 0 and fromt he first parameter after the
name of the compile (normally Java)
--------------------------------------------------------------------------------
Answer 39)
Objective 10.1)
4) The set is designed for unique elements.
Collection is an interface, not a class. The Collection interface includes a
method called iterator. This returns an instance of the Iterator class which has
some similarities with Enumerators.The name set should give away the purpose
of the Set interface as it is analogous to the Set concept in relational
databases which implies uniquness.
--------------------------------------------------------------------------------
Answer 40)
Objective 8.1)
2) If multiple listeners are added to a component the events will be
processed for all but with no guarantee in the order4) 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 41)
Objective 5.1)
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 42)
Objective 7.3)
2) You can obtain a mutually exclusive lock on any object3) A thread can
obtain a mutually exclusive lock on a synchronized method of an object4)
Thread scheduling algorithms are platform dependent
Yes that says dependent and not independent.
--------------------------------------------------------------------------------
Answer 43)
Objective 6.1)
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 44)
Objective 4.1)
1) An inner class may be defined as static4) 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 45)
Objective 5.3)
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 46)
Objective 5.1)2)j= i<
--------------------------------------------------------------------------------
Answer 47)
Objective 5.3)
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 mean8|4
To convert this to binary means1000
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 48)
Objective 5.1)
2)s+=i;
Only a String acts as if the + operator were overloaded
--------------------------------------------------------------------------------
Answer 49)
Objective 10.1)
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 50)
Objective 5.1)1)o1=o2;
2)b=ob;
4)o1=b;
--------------------------------------------------------------------------------
Answer 51)
Objective 5.4)
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 52)
Objective 6.2)
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 53)
Objective 6.2)
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 54)
Objective 4.1)
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 55)
Objective 7.2)
1) yield()2) sleep4) 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 56)
Objective 10.1)
1) addElement
--------------------------------------------------------------------------------
Answer 57)
Objective 4.1)
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 modifier4) An
interface cannot be instantiated
--------------------------------------------------------------------------------
Answer 58)
Objective 4.6)
1) mousePressed(MouseEvent e){}4) componentAdded(ContainerEvent e){}
--------------------------------------------------------------------------------
Answer 59)
Objective 10.1)
1) iterator2) isEmpty3) toArray
--------------------------------------------------------------------------------
Answer 60)
Objective 7.3)
2) 2) Ensures only one thread at a time may access a method or object
--------------------------------------------------------------------------------
End of documentMarcus Green copyright 2000
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -