Answer to Question 21)
3) The default constructor takes no parameters
4) The default constructor
is not created if the class has any constructors of its own.
Option 1 is fairly obviously wrong as constructors never have a return type. Option 2 is very dubious as well as Java does not offer void as a type for a method or constructor.
Answer to Question 22)
1) All of the variables in an interface are implicitly static
2) All of
the variables in an interface are implicitly final
3) All of the methods in
an interface are implictly abstract
All the variables in an interface are implicitly static and final. Any methods in an interface have no body, so may not access any type of variable
Answer to Question 23)
2) The + operator is overloaded for concatenation for the String class
In Java Strings are implemented as a class within the Java.lang package with the special distinction that the + operator is overloaded. If you thought that the String class is implemented as a char array, you may have a head full of C/++ that needs emptying. There is not "wrapper class" for String as wrappers are only for primitive types.
If you are surprised that option 4 is not a correct answer it is because length is a method for the String class, but a property for and array and it is easy to get the two confused.
Answer to Question 24)
1) A method in an interface must not have a body
3) A class may extends
one other class plus many interfaces
A class accesses an interface using the implements keyword (not uses)
Answer to Question 25)
3) The following statement will produce a result of zero, System.out.println(1 >>1);
Although you might not know the exact result of the operation -1 >>> 2 a knowledge of the way the bits will be shifted will tell you that the result is not plus 1. (The result is more like 1073741823 ) There is no such Java operator as the unsigned left shift. Although it is normally used for storing characters rather than numbers the char Java primitive is actually an unsigned integer type.
Answer to Question 26)
2) Arrays are initialized to default values wherever they are created
You can find the size of an array using the length field. The method
length is used to return the number of characters in a String. An array
can contain elements of any type but they must all be of the same type. The size
of an array is fixed at creation. If you want to change its size you can of
course create a new array and assign the old one to it. A more flexible approach
can be to use a collection class such as Vector.
Answer to Question 27)
2) Output of "Hello Crowle"
This code is an example of a short circuited operator. Because the first operand of the || (or) operator returns true Java sees no reason to evaluate the second. Whatever the value of the second the overall result will always be true. Thus the method called place is never called.
Answer to Question 28)
4) none of the above;
You may access methods of a direct parent class through the use of super but classes further up the hierarchy are not visible.
Answer to Question 29)
2) A method with the same name completly replaces the functionality of a method earlier in the hierarchy
Option 3 is more like a description of overloading. I like to remind myself of the difference between overloading and overriding in that an overriden method is like something overriden in the road, it is squashed, flat no longer used and replaced by something else. An overloaded method has been given extra work to do (it is loaded up with work), but it is still being used in its original format. This is just my little mind trick and doesn't match to anything that Java is doing.
Answer to Question 30)
2) The / operator is used to divide one value by another
3) The # symbol
may not be used as the first character of a variable
The % is the modulo operator and returns the remainder after a division. Thus
10 % 3=1
The $ symbol may be used as the first character of a variable, but
I would suggest that it is generally not a good idea. The # symbol cannot be
used anywhere in the name of a variable. Knowing if a variable can start with
the # or $ characters may seem like arbitrary and non essential knowlege but
questions like this do come up on the exam.
Answer to Question 31)
1) The default layout manager for an Applet is FlowLayout
4) The
FlowLayout manager attempts to honor the preferred size of any components
The default layout manager fror an Application is BorderLayout. An applet will use the default of FlowLayout if one is not specifically applied.
Answer to Question 32)
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.
Answer to Question 33)
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 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.
Answer to Question 34)
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.
Answer to Question 35)
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.
Answer to Question 36)
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.
Answer to Question 37)
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.
Answer to Question 38)
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) 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.
Answer to Question 39)
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.
Answer to Question 40)
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.