Solutions to All Questions


[51] public class Answer extends File implements Serializable

Explanation:

* * * *

[52] public final class someclassname extends somesuperclassname

Explanation:

* * * *

[53] 1,3

Explanation:
Please note that 2 is not correct. A package statement may appear before an import statement. A class constructor may be declared private also. Hence 4 is incorrect.
* * * *

[54] 1

Explanation:
Not available
* * * *

[55] 2

Explanation:
Both Strings test and test2 contain "abcd" . They are however located at different memory addresses. Hence test == test2 returns false, and test.equals(test2) returns true.
* * * *

[56] 5

Explanation:
A data member that does not have public/protected/private is accessible to all methods in the same package.
* * * *

[57] ActionListener

Explanation:

* * * *

[58] 3

Explanation:
Options 1 and 2 will produce -5 and option 4 will not compile because the Min method requires 2 parameters.
* * * *

[59] 4

Explanation:
The | is known as the Or operator, you could think of it as the either/or operator. Turning the numbers into binary gives
4 = 100
3 = 011
For each position, if either number contains a 1 the result will contain a result in that position. As every position contains a 1 the result will be
111, Which is decimal 7.
* * * *

[60] 3

Explanation:
The error is caused because run should have a void not an int return type.

Any class that is implements an interface must create a method to match all of the methods in the interface.The Runnable interface has one method called run that has a void return type.The sun compiler gives the error
Method redefined with different return type: int run() was defined as void run();

* * * *

[61] 3

Explanation:
Prefixing a number with a zero indicates that it is in Octal format. Thus when printed out it gets converted to base ten. 012 in octal means the first column from the right has a value of 2 and the next along has a value of one times eight.In decimal that adds up to 10.
* * * *

[62] 1

Explanation:
The Set interface ensures that its elements are unique, but does not order the elements. In reality you probably wouldn't create your own class using the Set interface.You would be more likely to use one of the JDK classes that use the Set interface such as ArraySet.
* * * *

[63] 1

Explanation:
Although there is a Runtime.gc(), this only suggests that the Java Virtual Machine does its garbage collection. You can never be certain when the garbage collector will run.This uncertainty can cause consternation for C++ programmers who wish to run finalize methods with the same intent as they use destructor methods.
* * * *

[64] 4

Explanation:
The reference to unique sequence of bits was an attempt to mislead because of the use of the word Set in the name bitset. Normally something called a set implies uniqueness of the members, but not in this context.
* * * *

[65] 4

Explanation:
Using the package statement has an effect similar to placing a source file into a different directory. Because the files are in different packages they cannot see each other.The stuff about File1 not having been compiled was just to mislead, java has the equivalent of an "automake", whereby if it was not for the package statements the other file would have been automatically compiled.
* * * *

[66] 3

Explanation:
The legal types for the switch expression are byte, short, char, and int. The constant case expressions can be any expression that is assignable to the type of the switch expression. 'd'-'a'=3. ~0=-1. 4&5=4.
* * * *

[67] 1

Explanation:
Since each iteration of the loop prints the value of the switch expression, it should be possible to figure out what is going on here.If more information is needed, then change the print statement so that the values of i and j are printed separately in columns.
* * * *

[68] 7

Explanation:
Methods m1(), m2(), m3(), m4(), m5(), and m6() throw subclasses of RuntimeException. Any exception that is a direct subclass of RuntimeException should not be caught and should not be declared in the throws clause of a method.
* * * *

[69] 2

Explanation:
The nested catch block is able to catch a Level2Exception or any subclass of it causing b to be incremented. Both of the finally blocks are then executed.
* * * *

[70] 2

Explanation:
The case 2 statement is processed on the first iteration followed by case 4 and then the default case. Case 2 causes the switch statement to complete.Case 4 processes the continue label2 statement which causes control to transfer to the boolean expression of the do-loop. The default case causes control to transfer out of the outer for-loop.
* * * *

[71] 1,3,4,6

Explanation:
Every class declared within the body of another class or interface is known as a nested class. If the nested class does not have a name then it is an anonymous class. If the nested class has a name then it is not anonymous.If the nested class has a name and is not declared inside of a block then it is a member class. If the member class is not static then it is an inner class. If the class is not nested then it is a top level class.Chapter 8 of the Java Language Specification defines class declarations. Section 8.1.2 of the JLS defines inner classes. Section 8.5 of the JLS defines member classes. Section 15.9.5 of the JLS defines anonymous class declarations.
* * * *

[72] 2

Explanation:
There is another access control modifier, which is the total lack of a modifier. Some authors refer to this as friendly access. Other authors refer to it as package access.
* * * *

[73] 1

Explanation:

* * * *

[74] 1,3,4,5

Explanation:
No explanation available
* * * *

[75] 4

Explanation:
After the execution of stop() method, thread won't execute any more statements.
* * * *

[76] 2

Explanation:
You can't override an non-static method with static method.
* * * *

[77] 4

Explanation:
No explanation available
* * * *

[78] 4

Explanation:
Constructors can be marked public, private or protected. Constructors do not have a return type.
* * * *

[79] 1,4

Explanation:
Be aware that Integer (not the upper case I) is a wrapper class and thus cannot be treated like a primitive. The fact that option 1 will compile may be a surprise, but although the char type is normally used to store character types,it is actually an unsigned integer type. The reason option 3 does not compile is that Java has a >>> operator but not a <<< operator. ;>> operator but not a <<< operator.
* * * *

[80] 4

Explanation:
You may access methods of a direct parent class through the use of super but classes further up the hierarchy are not visible.
* * * *

[81] 1,4

Explanation:
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.How could a programmer provide a constructor for an anonymous class?. Remember a constructor is a method with no return type and the same name as the class. Inner classes may be defined as private.
* * * *

[82] 1

Explanation:
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.
* * * *

[83] 1

Explanation:
This is a bit of a sneaky one as the Math.random method returns a pseudo random number between 0 and 1, and thus option 3 is a plausible Answer.However the number returned is a double and so the compiler will complain that a cast is needed to convert a double to an int.
* * * *

[84] 2

Explanation:
Please see the Java Language Specification
* * * *

[85] 7

Explanation:
It is not possible to invoke the print() method in A from an instance method in class C. The method in C needs to call a method in a super class two levels up. The super.super.print() strategy will not work, since super is a keyword, not anattribute. If the member to be accessed had been an instance variable, the solution would be to cast the 'this' reference to the class of the desired member and use the resulting reference to access the variable. Variable access is determinedby the declared type of the reference, where as the method to execute is determined by the actual type of the object denoted by the reference.
* * * *

[86] 2,4,5

Explanation:
The condition expression in a while header is not optional. It is not possible to break out of an if statement. Notice that if the 'if' statement had been placed within a labeled block, a switch statement or a loop construct, the usage of breakwould be valid.
* * * *

[87] 1

Explanation:
Please see Java Language Specification.
* * * *

[88] 2,5,6

Explanation:
void run() is the only method specified in Runnable interface. All the methods in the class Thread are public. notify() and notifyAll() doesn't take any argument. wait(), notify() & notifyAll() are all part of class Object and implicitlyinherited by all the classes in Java. For detailed explanations, please see the Threads part of Java Language Specification.
* * * *

[89] 3

Explanation:
Please see the Java Language Specification.
* * * *

[90] 3

Explanation:
Here the main method was just overloaded, so it won't give any compilation error.
* * * *

[91] 1

Explanation:
16 >> 1 is 8 and 17 >> 1 also 8.
* * * *

[92] 4

Explanation:
Java allows you to use ~ operator for integer type variables. The simple way to calculate is ~i = (- i) - 1.
* * * *

[93] 2

Explanation:
Here the variable 'b' will go upto 127. After that overflow will occur, so 'b' will be set to -ve value, the loop ends and prints "Welcome to Java".
* * * *

[94] 1,2,3

Explanation:
(From Marcus Green's Question of the day)
* * * *

[95] 3

Explanation:
The line labeled (1) will be allowed during compilation, since assignment is done from a subclass reference to a superclass reference. The line labeled (2) convinces the compiler that arrA will refer to an object that can bereferenced by arrB, and this will work when run, since arrA will refer to an object of type B[]. The line labeled (3) also convinces the compiler that arrA will refer to an object that can be referenced by arrB.This will not work when run, since arrA will refer to an object of type A[].
* * * *

[96] 1

Explanation:
The String class has its own implementation of the hashCode method. If it did not it would have inherited the hashCode method from Object which simply returns the memory address of the class instance.
* * * *

[97] 1,2,3

Explanation:
No explanation available.
* * * *

[98] 1,2,3

Explanation:
Note that this question asks what can cause a thread to stop executing, not what will cause a thread to stop executing. Java threads are somewhat platform dependent and you should becarefull when making assumptions about Thread priorities. On some platforms you may find that a Thread with higher priorities gets to "hog" the processor.
* * * *

[99] 4

Explanation:
This one is a trick question that needs some assumption. Since main() is static only static members of the class are accessible within main(). Here xyz is not static. Hence this.xyz is not accessible from main() under any circumstances(with any access specified). "This" is entirely different from "this". But no information has been given in the question about "This". So you have to assume that there is a class instance called "This" and you are accessing the xyz variablebound to that instance.
* * * *

[100] 2,3

Explanation:
Creating a class with runnable still requires access to the Thread class. The class implementing Runnable is passed as a constructor parameter to an instance of Thread.
* * * *


2001-2003 Technopark. Developed by: Giri Mandalika