📄 scjp试题-scjpmockexam2.txt
字号:
Answer to Question 32)
Objective 1.2)
3) Only one instance of a static variable will exist for any amount of class instances
Option 1) is more a description of a final variable. Option 2 is designed to fool Visual Basic programmers like me as this is how you can use the keyword static in VB. The modifier static can be applied to a class, method or variable.
http://www.jchq.net/tutorial/01_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 33)
Objective 11.1)
1) Java uses a system called UTF for I/O to support international character sets
3) An instance of FileInputStream may not be chained to an instance of FileOutputStream
4) File I/O activities requires use of Exception handling
Internally Java uses Unicode which are 16 bit characters. For I/O Java uses UTF which may be more thatn 16 bits per chamore thatn 16 bits per character.
Generally InputStreams can only be chained to other InputStreams and OutputStreams can only be chained to other OutputStreams. The piped streams are an exception to this.
http://www.jchq.net/tutorial/11_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 34)
Objective 1.2)
1) Compile time error
It wil produce an error like "Abstract and native method can't have a body. This is typical of the more misleading question where you might think it is asking you about the circumstances under which the finally clause runs, but actually it is about something else.
http://www.jchq.net/tutorial/07_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 35)
Objective 7.1)
2) Compilation and run with the output "Running"
This is perfectly legitimate if useless sample of creating an instnace of a Thread and causing its run method to execute via a call to the start method. The Thread class is part of the core java.lang package and does not need any explicit import statement. The reference to a Thread target is an attempt to mislead with a reference to the method of using the Runnable interface instead of simply inheriting from the Thread super class.
http://www.jchq.net/tutorial/07_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 36)
Objective 11.1)
1) RandomAccessFile raf=new RandomAccessFile("myfile.txt","rw");
The RandomAccessFile is an anomaly in the Java I/O architecture. It descends directly from Object and is not part of the Streams architecture.
http://www.jchq.net/tutorial/11_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 37)
Objective 6.2)
2) public int amethod(int i, int j) {return 99;}
3) protected void amethod (long l){}
4) private void anothermethod(){}
Option 1 will not compile on two counts. One is the obvious one that it claims to return an integer. The other is that it is effectivly an attempt to redefine a method within the same class. The change of name of the parameter from i to z has no effect and a method cannot be overriden within the same class.
http://www.jchq.net/tutorial/06_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 38)
Objective 8.1)
1) Code must be written to cause a frame to close on selecting the system close menu
2) The default layout for a Frame is the BorderLayout Manager
4) ThrLayout Manager
4) The GridBagLayout manager makes extensive use of the the GridBagConstraints class.
You can change the layout manager for a Frame or any other container whenever you like.
http://www.jchq.net/tutorial/08_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 39)
Objective 1.2)
4) The code will compile without error
There are no restrictions on the level of nesting for inner/nested classes. Inner classes may be marked private. The main method is not declared as public static void main, and assuming that the commandline was java Droitwich it would not be invoked anyway.
http://www.jchq.net/tutorial/01_02Tut.htm
Answer to Question 40)
Objective 1.2)
1) super.oak=1;
2) oak=33;
3) Base.oak=22;
Because the variable oak is declared as static only one copy of it will exist. Thus it can be changed either through the name of its class or through the name of any instance of that class. Because it is created as an integer it canot be assigned a fractional component without a cast.
http://www.jchq.net/tutorial/01_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 41)
Obje Question 41)
Objective 4.6)
4) Use the getText method of a Textfield and use the parseInt method of the Integer class
Here is an example of how you might do this
Integer.parseInt(txtInputValue.getText());
I'm not sure that a question on this actually will come up in the exam but it is a very useful thing to know in the real world.
http://www.jchq.net/tutorial/04_06Tut.htm
--------------------------------------------------------------------------------
Answer to Question 42)
Objective 4.6)
4) none of the above
The wrapper classes are immutable. Once the value has been set it cannot be changed. A common use of the wrapper classes is to take advantage of their static methods such as Integer.parseInt(String s) that will returns an integer if the the value has been set it cannot be changed. A common use of the wrapper classes is to take advantage of their static methods such as Integer.parseInt(String s) that will returns an integer if the String contains one.
http://www.jchq.net/tutorial/04_06Tut.htm
--------------------------------------------------------------------------------
Answer to Question 43)
Objective 6.2)
2) constructors cannot be overriden
Overloading constructors is a key technique to allow multiple ways of initialising classes. By definition constructors have noition constructors have no return values so option 3 makes no sense. Option 4 is the inverse of what happens as constructor code will execute starting from the oldest ancestor class downwards. You can test this by writing a class that inherits from a base class and getting the constructor to print out a message. When you create the child class you will see the order of constructor calling.
http://www.jchq.net/tutorial/06_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 44)
Objective 7.1)
yield is a static method and causes whatever thread is currently executing to yield its cycles.
1) t.yield();
2) yield()
http://www.jchq.net/tutorial/07_01Tut.htm
JavaDoc for the Thread class
http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Thread.html
--------------------------------------------------------------------------------
Answer to Question 45)
Objective 6.2)
4) Compilation and run with an output of 99
The fact that the variable court is declared as private does not stop the constructor from being able to initialise it.
http://www.jchq.net/tutorial/06_02Tut.htm
--------------------------------------------------------------------------------
Ans to Question 46)">Answer to Question 46)
to Question 46)">Answer to Question 46)
Objective 6.2)
3) To be overriden a method must have the same name, parameter and return types
Option 1 is a sneaky one in that it should read overriden not overloaded. An overriden method must also have the same return type. Parameter names are purely a programmer convenience and are not a factor in either overloading and overriding. Parameter order is a factor however.
http://www.jchq.net/tutorial/06_02Tut.htm
Answer to Question 47)
Objective 6.2)
1) Compile time error
With the sun JDK it will produce the following error
"Only constructors can invoke constructors".
If you took out the call to super that causes this error the program would compile and at runtime it would output Base and then Checket as constructors are called from the oldest ancestor class downwards.
http://www.jchq.net/tutorial/06_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 48)
Objective 1.2)
1) Static methods cannot be overriden to be non static
The JDK1.1 compiler will issue an error message "static methods cannot be overriden" if you atempt to do thiuot; if you atempt to do this. There is no logic or atempt to do this. There is no logic or reason why private methods should not be overloaded or that static methods should not be declared private. Option 4 is a jumbled up version of the limitations of exceptions for overriden methods
http://www.jchq.net/tutorial/01_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 49)
Objective 3.1)
2) A program can suggest that garbage collection be performed but not force it
4) A reference becomes eligable for garbage collection when it is assigned to null
If a program keeps creating new references without any being discarded it may run out of memory. Unlike most aspects of Java garbage collection is platform dependent.
http://www.jchq.net/tutorial/03_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 50)
Objective 1.2)
2) Compile time error
The main method is static and cannot access the non static variable x
http://www.jchq.net/tutorial/01_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 51)
Objective 1.2)
1) Compile time error
When compiled with JDK 1.1 the following error is produced.
1.1 the folloduced.
1.1 the following error is produced.
Abstract and native methods can't have a body: void hallow() abstract void hallow()
http://www.jchq.net/tutorial/01_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 52)
Objective 6.1)
3) Create and employee class with fields for Job title and fields for the other values.
These questions can appear tricky as the whole business of designing class structures is more art than science. It is asking you to decide if an item of data is best represented by the "Is a" or "Has a" relationship. Thus in this case any of the job titles mentioned will always refer to something that "Is a" employee. However the employee "has a" job title that might change.
One of the important points is to ask yourself when creating a class "Could this change into another class at some point in the future". Thus in this example an apprentice chef would hope one day to turn into a chef and if she is very good will one day be head chef. Few other mock exams seem to have this type of questions but they di come up in the real exam.
http://www.jchq.net/tutorial/06_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 53)
Objective 11.1)
3) new BufferedReader(new InputStreamReader(new FileInputStream("file.name")));
The key to this question is that it asks about tens of megabytes of data, implying that performance is an issue. A Buffered Reader will optimise the performance of accessing a file. Although the objectives do not specifically mention it questions on I/O do come up on the exam.
http://www.jchq.net/tutorial/11_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 54)
Objective 5.4)
4) Output of 0
The method fermin only receives a copy of the variable i and any modifications to it are not reflected in the version in the calling method. The post increment operator ++ effectivly modifes the value of i after the initial value has been assiged to the left hand side of the equals operator. This can be a very tricky conept to understand
http://www.jchq.net/tutorial/05_04Tut.htm
--------------------------------------------------------------------------------
Answer to Question 55)
Objective 2.2)
1) Compile time error
This might be considered a "gocha" or deliberate attempt to mislead you because i has been given the data type of long and the parameter must be of long and the parameter must be either a byte, char, short or int. If you attempt to compile this code with JDK 1.2 you will get an error that says something like "Incompatible type for switch, Explicit cast needed to convert long to int. Answering with option 2 would have been reasonable because if the parameter had been an integer type the lack of break statements would have caused this output. If you gave either of the answers you should probably revise the subject.
http://www.jchq.net/tutorial/02_02Tut.htm
Answer to Question 56)
Objective 5.1)
1) System.out.println(i++);
3) System.out.println(i);
4) System.out.println(i--);
The options for this question might look suspiciously easy if you are not aware of the effects of the post-increment operators. The ++ and -- operations for examples 1 and 4 only come into effect after the output operations, ie after whatever else is done to them on that line of code. Option 2 should be fairly obvious as you should know that the single quote characters indicate a char value, ie storing the character rather than the numberical value for 0.
http://www.jchq.net/tutorial/05_01Tut.htm
--------------------------------------------------------------------------------
Answer to Question 57)
Objective 6.2)
4) System.out.println( ((Agg) a).getFields());
The Base type reference to the ins
The Base type reference to the instance of the class Agg needs to be cast from Base to Agg to get access to its methods.The method invoked depends on the object itself, not on the declared type. So, a.getField() invokes getField() in the Base class, which displays Base. But the call to ((Agg)a).getField() will invoke the getField() in the Agg class. You will be unlucky to get a question as complex as this on the exam.
http://www.jchq.net/tutorial/06_02Tut.htm
--------------------------------------------------------------------------------
Answer to Question 58)
Objective 4.4)
2) compilation and output of false
A variable defined at class level will always be given a default value and the default value for the primitive type boolean is false
http://www.jchq.net/tutorial/04_04Tut.htm
--------------------------------------------------------------------------------
Answer to Question 59)
Objective 4.6)
1) The x,y coordinates of an instance of MouseEvent can be obtained using the getX() and getY() methods
4) The time of a MouseEvent can be extracted using the when parameter of the MouseEvent constructor
If you chose option 4, referring to the mythical getTime method you have mad
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -