What will be the output of the program?
import java.util.*;
public class NewTreeSet2 extends NewTreeSet
{
public static void main(String [] args)
{
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protected class NewTreeSet
{
void count()
{
for (int x = 0; x < 7>
Which of the following class level (nonlocal) variable declarations will not compile?
Which two of the following are legal declarations for nonnested classes and interfaces?
1.final abstract class Test {}
2.public static interface Test {}
3.final public class Test {}
4.protected abstract class Test {}
5.protected interface Test {}
6.abstract public class Test {}
What is the widest valid returnType for methodA in line 3?
public class ReturnIt
{
returnType methodA(byte x, double y) /* Line 3 */
{
return (long)x / y * 2;
}
}
Which three are valid method signatures in an interface?
1.private int getArea();
2.public float getVol(float x);
3.public void main(String [] args);
4.public static void main(String [] args);
5.boolean setFlag(Boolean [] test);
Which cause a compiler error?
What allows the programmer to destroy an object x?
public Object m()
{
Object o = new Float(3.14F);
Object [] oa = new Object[l];
oa[0] = o; /* Line 5 */
o = null; /* Line 6 */
oa[0] = null; /* Line 7 */
return o; /* Line 8 */
}
When is the Float object, created in line 3, eligible for garbage collection?
class Test
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}
When is the Demo object eligible for garbage collection?
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Point X */
{
runTest();
}
}
At Point X on line 5, which code is necessary to make the code compile?
Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );
Which statement is true?
Which three statements are true?
1.Assertion checking is typically enabled when a program is deployed.
2.It is never appropriate to write code to handle failure of an assert statement.
3.Assertion checking is typically enabled during program development and testing.
4.Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
5.Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() {}
}
import java.awt.Button;
class CompareReference
{
public static void main(String [] args)
{
float f = 42.0f;
float [] f1 = new float[2];
float [] f2 = new float[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}
which three statements are true?
1.f1 == f2
2.f1 == f3
3.f2 == f1[1]
4.x == f1[0]
5.f == f1[0]
What will be the output of the program?
class SSBool
{
public static void main(String [] args)
{
boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */
System.out.print("ok ");
if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/
System.out.println("dokey");
}
}
What is the numerical range of a char?
Which one is a valid declaration of a boolean?
Which four options describe the correct default values for array elements of the types indicated?
1.int -> 0
2.String -> "null"
3.Dog -> null
4.char -> '\u0000'
5.float -> 0.0f
6.boolean -> true
Total number of questions : 20
Number of answered questions : 0
Number of unanswered questions : 20
What will be the output of the program?
import java.util.*;
public class NewTreeSet2 extends NewTreeSet
{
public static void main(String [] args)
{
NewTreeSet2 t = new NewTreeSet2();
t.count();
}
}
protected class NewTreeSet
{
void count()
{
for (int x = 0; x < 7>
Your Answer : (Not Answered)
Correct Answer : D
Nonnested classes cannot be marked protected (or final for that matter), so the compiler will fail at protected class NewTreeSet.
Which of the following class level (nonlocal) variable declarations will not compile?
Your Answer : (Not Answered)
Correct Answer : C
Option C will not compile; the synchronized modifier applies only to methods.
Option A and B will compile because protected and transient are legal variable modifiers. Option D will compile because volatile is a proper variable modifier.
Which two of the following are legal declarations for nonnested classes and interfaces?
1.final abstract class Test {}
2.public static interface Test {}
3.final public class Test {}
4.protected abstract class Test {}
5.protected interface Test {}
6.abstract public class Test {}
Your Answer : (Not Answered)
Correct Answer : C
(3), (6). Both are legal class declarations.
(1) is wrong because a class cannot be abstract and final—there would be no way to use such a class. (2) is wrong because interfaces and classes cannot be marked as static. (4) and (5) are wrong because classes and interfaces cannot be marked as protected.
What is the widest valid returnType for methodA in line 3?
public class ReturnIt
{
returnType methodA(byte x, double y) /* Line 3 */
{
return (long)x / y * 2;
}
}
Your Answer : (Not Answered)
Correct Answer : A
However A, B and C are all wrong. Each of these would result in a narrowing conversion. Whereas we want a widening conversion, therefore the only correct answer is D. Don't be put off by the long cast, this applies only to the variable x and not the rest of the expression. It is the variable y (of type double) that forces the widening conversion to double.
Java's widening conversions are:
- From a byte to a short, an int, a long, a float, or a double.
- From a short, an int, a long, a float, or a double.
- From a char to an int, a long, a float, or a double.
- From an int to a long, a float, or a double.
- From a long to a float, or a double.
- From a float to a double.
Which three are valid method signatures in an interface?
1.private int getArea();
2.public float getVol(float x);
3.public void main(String [] args);
4.public static void main(String [] args);
5.boolean setFlag(Boolean [] test);
Your Answer : (Not Answered)
Correct Answer : B
(2), (3), and (5). These are all valid interface method signatures.
(1), is incorrect because an interface method must be public; if it is not explicitly declared public it will be made public implicitly. (4) is incorrect because interface methods cannot be static.
Which cause a compiler error?
Your Answer : (Not Answered)
Correct Answer : B
Option B generates a compiler error:
To correct the problem and make option B compile you need to add an extra pair of curly brackets:
int [ ] [ ] scores = { {2,7,6}, {9,3,45} };
What allows the programmer to destroy an object x?
Your Answer : (Not Answered)
Correct Answer : D
Option D is correct. When an object is no longer referenced, it may be reclaimed by the garbage collector. If an object declares a finalizer, the finalizer is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. When a class is no longer needed, it may be unloaded.
Option A is wrong. I found 4 delete() methods in all of the Java class structure. They are:
None of these destroy the object to which they belong.
Option B is wrong. I found 19 finalize() methods. The most interesting, from this questions point of view, was the finalize() method in class java.lang.Object which is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. This method does not destroy the object to which it belongs.
Option C is wrong. But it is interesting. The Runtime class has many methods, two of which are:
public Object m()
{
Object o = new Float(3.14F);
Object [] oa = new Object[l];
oa[0] = o; /* Line 5 */
o = null; /* Line 6 */
oa[0] = null; /* Line 7 */
return o; /* Line 8 */
}
When is the Float object, created in line 3, eligible for garbage collection?
Your Answer : (Not Answered)
Correct Answer : C
Option A is wrong. This simply copies the object reference into the array.
Option B is wrong. The reference o is set to null, but, oa[0] still maintains the reference to the Float object.
Option C is correct. The thread of execution will then not have access to the object.
class Test
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}
When is the Demo object eligible for garbage collection?
Your Answer : (Not Answered)
Correct Answer : D
Option D is correct. By a process of elimination.
Option A is wrong. The variable d is a member of the Test class and is never directly set to null.
Option B is wrong. A copy of the variable d is set to null and not the actual variable d.
Option C is wrong. The variable d exists outside the start() method (it is a class member). So, when the start() method finishes the variable d still holds a reference.
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Point X */
{
runTest();
}
}
At Point X on line 5, which code is necessary to make the code compile?
Your Answer : (Not Answered)
Correct Answer : B
Option B is correct. This works because it DOES throw an exception if an error occurs.
Option A is wrong. If you compile the code as given the compiler will complain:
"unreported exception must be caught or declared to be thrown" The class extends Exception so we are forced to test for exceptions.
Option C is wrong. The catch statement belongs in a method body not a method specification.
Option D is wrong. TestException is a subclass of Exception therefore the test method, in this example, must throw TestException or some other class further up the Exception tree. Throwing RuntimeException is just not on as this belongs in the java.lang.RuntimeException branch (it is not a superclass of TestException). The compiler complains with the same error as in A above.
Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
Your Answer : (Not Answered)
Correct Answer : D
The casting to an int is a smokescreen. Use a process of elimination to answer this question:
Option D is the correct answer, it is syntathecially correct and will consistently return a value less than d.
Option A and B are wrong because both the min() and max() methods require 2 arguments whereas here they are passed only one parameter.
Option C is wrong because it could return a value greater than d (if d was negative).
What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );
Your Answer : (Not Answered)
Correct Answer : B
The Math.random() method returns a number greater than or equal to 0 and less than 1 . Since we can then be sure that the sum of that number and 2.5 will be greater than or equal to 2.5 and less than 3.5, we can be sure that Math.round() will round that number to 3. So Option B is the answer.
Which statement is true?
Your Answer : (Not Answered)
Correct Answer : D
Option D is correct.
Option C is wrong. See the note above on Islands of Isolation (An object is eligible for garbage collection when no live thread can access it - even though there might be references to it).
Option B is wrong. "Never again be used" does not mean that there are no more references to the object.
Option A is wrong. Even though Java applications can run out of memory there another answer supplied that is more right.
Which three statements are true?
1.Assertion checking is typically enabled when a program is deployed.
2.It is never appropriate to write code to handle failure of an assert statement.
3.Assertion checking is typically enabled during program development and testing.
4.Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
5.Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
Your Answer : (Not Answered)
Correct Answer : B
(1) is wrong. It's just not true.
(2) is correct. You're never supposed to handle an assertion failure.
(3) is correct. Assertions let you test your assumptions during development, but the assertion code—in effect—evaporates when the program is deployed, leaving behind no overhead or debugging code to track down and remove.
(4) is wrong. See the explanation for (5) below.
(5) is correct. Assertion checking can be selectively enabled or disabled on a per-package basis. Note that the package default assertion status determines the assertion status for classes initialized in the future that belong to the named package or any of its "subpackages".
The assertion status can be set for a named top-level class and any nested classes contained therein. This setting takes precedence over the class loader's default assertion status, and over any applicable per-package default. If the named class is not a top-level class, the change of status will have no effect on the actual assertion status of any class.
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() {}
}
Your Answer : (Not Answered)
Correct Answer : C
There is no exception thrown, so all the code with the exception of the catch statement block is run.
import java.awt.Button;
class CompareReference
{
public static void main(String [] args)
{
float f = 42.0f;
float [] f1 = new float[2];
float [] f2 = new float[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}
which three statements are true?
1.f1 == f2
2.f1 == f3
3.f2 == f1[1]
4.x == f1[0]
5.f == f1[0]
Your Answer : (Not Answered)
Correct Answer : B
(2) is correct because the reference variables f1 and f3 refer to the same array object.
(4) is correct because it is legal to compare integer and floating-point types.
(5) is correct because it is legal to compare a variable with an array element.
(3) is incorrect because f2 is an array object and f1[1] is an array element.
What will be the output of the program?
class SSBool
{
public static void main(String [] args)
{
boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */
System.out.print("ok ");
if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/
System.out.println("dokey");
}
}
Your Answer : (Not Answered)
Correct Answer : B
The & operator has a higher precedence than the | operator so that on line 8 b1 and b2 are evaluated together as are b2 & b3. The final b1 in line 10 is what causes that if test to be true. Hence it prints "dokey".
What is the numerical range of a char?
Your Answer : (Not Answered)
Correct Answer : D
A char is really a 16-bit integer behind the scenes, so it supports 216 (from 0 to 65535) values.
Which one is a valid declaration of a boolean?
Your Answer : (Not Answered)
Correct Answer : C
A boolean can only be assigned the literal true or false.
Which four options describe the correct default values for array elements of the types indicated?
1.int -> 0
2.String -> "null"
3.Dog -> null
4.char -> '\u0000'
5.float -> 0.0f
6.boolean -> true
Your Answer : (Not Answered)
Correct Answer : B
(1), (3), (4), (5) are the correct statements.
(2) is wrong because the default value for a String (and any other object reference) is null, with no quotes.
(6) is wrong because the default value for boolean elements is false.
Total number of questions : 20
Number of answered questions : 0
Number of unanswered questions : 20
We'll write only best content for you