Professional Documents
Culture Documents
All Questions With Solutions: #1 Given
All Questions With Solutions: #1 Given
All Questions With Solutions: #1 Given
Solutions
#1 Given:
(1) 2
(2) 4
(3) 6
(4) 7
Answer : 2
Explanation :
Option 2 is correct because t will result in a value
of 4. The ++ operator will increment variables by
one. Stepping through the for loop until p < 5,
incrementing the variables, and performing the
calculation will result in t being equal to 4.
#6 Given:
1. class IntType {
2. public String getType(String a, int b,
char c) {
3. String holdit1 = new String();
4. holdit1 = a;
5. return holdit1;
6. }
7. }
8.
9. class OverType extends IntType {
10.
11. String holdit2 = new String();
12. holdit2 = holdit2.concat("This is
").concat(a);
13. return holdit2;
14. }
15.
16. public static void main(String args[]) {
17. OverType ot = new OverType();
18. String x = new String("x");
19. int y = 1;
20. char z = 'b';
21. System.out.println(ot.getType(x, y,
z));
22. }
23. }
1. import java.awt.*;
2.
3. public class Birthdays extends Frame {
4. Birthdays() {
5. super("Birthday Reminder");
6. String lblsP1[] = {"Name:",
"Birthday:", "Address:"};
7. String butnsP2[] = {"Add", "Save",
"Exit"};
8. Panel panelTop = new Panel();
9. Panel panelBot = new Panel();
10. panelTop.setLayout(new
GridLayout(3,2,3,3));
11. for(int x = 0; x < lblsP1.length; x++)
{
12. panelTop.add(new Label(lblsP1[x]));
13. panelTop.add(new TextField());
14. }
15. for(int y = 0; y < butnsP2.length; y+
+) {
16. panelBot.add(new
Button(butnsP2[y]));
17. }
18. add(panelTop, BorderLayout.NORTH);
19. add(panelBot, BorderLayout.SOUTH);
20. }
21. }
(1) Value is 5
Value is 6
(2) This value is 5
This value is 6
(3) Value is 5
This value is 6
(4) This value is 5
Value is 6
(5) I was passed 5
I was passed 6
Answer : 3
Explanation :
3 is correct. The first message is produced by the
Base class when b1.method(5) is called and is
therefore Value is 5. Despite variable b2 being
declared as being of the Base class, the behavior
that results when method() is invoked upon it is
the behavior associated with class of the actual
object, not with the type of the variable. Since the
object is of class Sub, not of class Base, the
second message is generated by line 3 of class
Sub: This value is 6.
#1 Consider the following class definition:
6
1. public class Test extends Base {
2. public Test(int j) {
3. }
4. public Test(int j, int k) {
5. super(j, k);
6. }
7. }
(1) Base() { }
(2) Base(int j) { }
(3) Base(int j, int k) { }
(4) Base(int j, int k, int l) { }
Answer : 1,3
Explanation :
1 and 3 are correct. In the constructor at lines 2
and 3, there is no explicit call to either this() or
super(), which means that the compiler will
generate a call to the zero argument superclass
constructor, as in 1. The explicit call to super() at
line 5 requires that the Base class must have a
7.constructor as in 3. This has two consequences.
First, 3 must be one of the required constructors
and therefore one of the answers.Second, the
Base class must have at least that constructor
defined explicitly, so the default constructor is not
generated, but must be added explicitly. Therefore
the constructor of 1 is also required and must be a
correct answer.At no point in the Test class is
there a call to either a superclass constructor with
one or three arguments, so 2 and 4 need not
explicitly exist.
#1 Which of the following statements are true?
8
(1) An inner class may be declared private
(2) An inner class may be declared static
(3) An inner class defined in a method should
always be anonymous
(4) An inner class defined in a method can access
all the method local variables
(5) Construction of an inner class may require an
instance of the outer class
Answer : 1,2,5
Explanation :
1, 2, and 5 are correct. Inner classes may be
defined with any accessibility, so private is entirely
acceptable and 1 is correct. Similarly, the static
modifier is permitted on an inner class, which
causes it not to be associated with any
particularinstance of the outer class. This means
that 2 is also correct. Inner classes defined in
methods may be anonymous--and indeed often
are--but this is not required, so 3 is wrong. 4 is
wrong because it is not possible for an inner class
defined in a method to access the local variables
of the method, except for those variables that are
marked as final. Constructing an instance of a
static inner class does not need an instance of the
enclosing object, but all non-static inner classes
do require such a reference, and that reference
must be available to the new operation. The
reference to the enclosing object is commonly
implied as this, which is why it is commonly not
explicit. These points make 5 true.
#1 Consider the following definition:
9
1. public class Outer {
2. public int a = 1;
3. private int b = 2;
4. public void method(final int c) {
5. int d = 3;
6. class Inner {
7. private void iMethod(int e) {
8.
9. }
10. }
11. }
12. }
(1) a
(2) b
(3) c
(4) d
(5) e
Answer : 1,2,3,5
Explanation :
1, 2, 3, and 5 are correct. Since Inner is not a
static inner class, it has a reference to an
enclosing object, and all the variables of that
object are accessible. Therefore 1 and 2 are
correct, despite the fact that b is marked
private.Variables in the enclosing method are only
accessible if those variables are marked final, so
the method argument c is correct, but the variable
d is not.Finally, the parameter e is of course
accessible, since it is a parameter to the method
containing line 8 itself.
#2 Which of the following statements are true?
0
(1) Given that Inner is a non-static class declared
inside a public class Outer, and appropriate
constructor forms are defined, an instance of
Inner may be constructed like this:
new Outer().new Inner()
(2) If an anonymous inner class inside the class
Outer is defined to implement the interface
ActionListener, it may be constructed like this:
new Outer().new ActionListener()
(3) Given that Inner is a non-static class declared
inside a public class Outer and appropriate
constructor forms are defined, an instance of
Inner may be constructed in a static method
like this:
new Inner()
(4) An anonymous class instance that implements
the interface MyInterface may be constructed
and returned from a method like this: 1.
return new MyInterface(int x) { 2. int x; 3.
public MyInterface(int x) { 4. this.x = x; 5. }
6. };
Answer : 1
Explanation :
1 is correct. Construction of a normal inner class
requires an instance of the enclosing class. Often
this enclosing instance is provided via the implied
this reference, but an explicit reference may be
used in front of the new operator, as shown in 1.
class K {
private void m1() {
J j = null;
for (int i = 0; i < 5; i++) {
j = new J(this, i); // 1
}
Runtime.getRuntime().gc(); // 2
synchronized (this) {
while (J.notFinalized() > 0) {
try {wait();} catch
(InterruptedException ie) {}
}
}
}
public static void main(String[] args) {
new K().m1();
}
}
(1) 0
(2) 1
(3) 4
(4) 5
(5) Can not be determined without more
information
(6) Compiler error
(7) Run time error
(8) None of the above
Answer : 3
Explanation :
Method K.m1 creates five objects of type J. Each
instance has a name represented by an integer
between 0 and 4 inclusive. If the garbage collector
does not run then the program will produce no
output.If the garbage collector does run then the
output of the program could be a series of integers
that are the names of four of the five objects. As
each new object is created its reference is
assigned to the reference variable j.The previously
referenced object then becomes eligible for
garbage collection. The last object created, 4, is
not available for garbage collection until method
m1 runs to completion.The while loop in the
synchronized block will never complete because
J.notFinalized will never return zero. This program
is intended to provide a working example of
garbage collecting objects referenced by local
variables.
#2 What is the output of the following code when
2 compiled and run? Select two correct answers
System.out.println(Integer.toBinaryString(i));
6 }
7}
(1) Prints 3
(2) Error during compilation at line 4
(3) Error during compilation at line 5
(4) Prints 11
(5) Prints 0
Answer : 4
Explanation :
First off, 017 is an octal integer literal having the
decimal value 15. Second, the cast to byte only
applies to j and not to j >> 2 as a whole. Thus, j
is downcast to byte and then upcast to int again
before the shifting.Briefly, the cast has no effect
here. Then, the binary sequence of 15 is
00000000 00000000 00000000 00001111, which,
shifted 2 bits to the right, yields 00000000
00000000 00000000 00000011. Finally, the binary
sequence, 11, is printed. Note that the prefixed
0's are dismissed.
#2 Select three correct statements:
4
(1) The garbage collection thread cannot outlive
the last user thread
(2) The garbage collection can be forced by
invoking System.gc().
(3) The garbage collection thread is a non-
deamon thread
(4) The finalize() method is invoked at most once
by the JVM for any given object
(5) The finalize() method may resurrect the object
upon which it has been invoked
Answer : 1,4,5
Explanation :
The garbage collection thread is a deamon thread.
The latter die when there are no more users
threads running. The garbage collection cannot be
forced.
#2 What is the output of the following code when
5 compiled and run? Select one correct answer.
import java.io.*;
public class TechnoSample {
public static void main(String[] args)
{
TechnoSampleSub myref =
new TechnoSampleSub();
try{
myref.test();
}catch(IOException ioe){}
}
void test() throws IOException{
System.out.println("In
TechnoSample");
throw new IOException();
}
}
class TechnoSampleSub extends
TechnoSample {
void test() {
System.out.println("In
TechnoSampleSub");
}
}
(1) Prints:
In TechnoSampleSub
(2) Prints:
In TechnoSample
(3) Prints:
In TechnoSample
In TechnoSampleSub
(4) Prints:
In TechnoSampleSub
In TechnoSample
(5) The code does not compile
Answer : 5
Explanation :
The code does not compile because no
IOException is thrown when invoking myref.test().
Note that myref's declared and runtime types are
TechnoSampleSuband thus no dynamic lookup will
be performed. However, if you change the
declared type to TechnoSample, the code will
compile and the correct answer would be A
because method test() isoverridden in
TechnoSampleSub
#2 What is the output of the following code when
6 compiled and run with the following command
line: java TechnoSample two three? Select
two correct answers.
class A{}
class B extends A implements E{} //line 1
class C extends A{}
class D extends B{}
interface E{}
public class Question07 {
public static void main(String[] args)
{
A a = new D(); //line 2
C c = new C(); //line 3
E e = (E)a; //line 4
B b = (B)e; //line 5
}
}
(1) 0
(2) 1
(3) 2
(4) 3
(5) 4
Answer : 4
Explanation :
We declare an array of Object of length two. We
then initialize each element to a new Object. We
have 2 objects in the array and the array itself
(which is an object, too!), that makes 3.
#2 What is the output of the following code when
9 compiled and run? Select one correct answer.
System.out.println("i = "+i);
else
throw new
Exception("i > 5");
} catch (Exception e){
System.err.println(e.getMessage()+"
(i="+i+")");
}
}
}
System.out.print(" "+j);
}
}
});
t.start();
}
}
(1) Prints 0 1 2 3 4
(2) Compilation error
(3) No output
(4) IllegalThreadStateException is thrown at
runtime
(5) Prints 0 1 2 3 4 5
Answer : 2
Explanation :
The code does not compile because the
anonymous inner class (new Runnable(){...}) tries
to access the non-final local variable i
#3 What is the output of the following code when
1 compiled and run? Select one correct answer.
System.out.println(buf1.toString());
}
System.out.println(b.delete(0,1).toString());
}
}
(1) Prints
Hello World
Hello World
(2) Prints
Hello orld
Hello orld
(3) Prints
Hello orld
ello orld
(4) Prints
ello orld
ello orld
(5) Compilation error
Answer : 4
Explanation :
Whenever you perform some operation upon a
String object, you will get a new String object if
the operation had some effect on the original
String, we say that a String is immutable and that
its sequence of characters cannot be
changed.Here, we are dealing with a StringBuffer
which is an implementation of a mutable String,
that is you can modify the character sequence it
contains. Whenever you perform an operation
upon a StringBuffer, the same StringBuffer(whose
content has been modified) is returned. The next
important thing to remember is that when a
reference to an object is passed as argument to a
method, a copy of the reference is actually passed
to the method. In this case,buf1 is passed to
addSomeStuff and replace is invoked upon it. The
changes operated by replace are affecting buf1.
We then store the reference to buf (which
references the same object as buf1 into a local
StringBuffer called b.
#3 What is the output of the following code when
2 compiled and run? Select two correct answers.
(Note: when an instance of a Vector is
printed, its content appear between square
brackets [])
import java.util.*;
public class TechnoSample {
public static void main(String[] args)
{
Vector col = new Vector();
col.add(new Integer(1));
col.add(new Integer("2"));
col.add(new Float(3.2d));
//line 1
col.add(col.elementAt(1));
col.setElementAt(col.elementAt(2),0);
System.out.println(col);
}
}
(1) Prints:
Hello
World!
(2) Prints Hello World!(linefeed is ignored)
(3) Compilation error
(4) Compiles fine, but an exception is thrown at
runtime
(5) Unicode characters like '\u0048' may be used
to create String literals
Answer : 3,5
Explanation :
This shows you that Unicode characters are
processed very early during the lexical parsing of
a Java source file. Here LF, which is a line
terminator, isactually translated to a line
terminator and this results in malformed Java
code. For instance, the example given above is
actually interpreted as:
String s = "Hello
World";
You can notice that the first line is unterminated
and the compiler lets you know that.
#3 What is the output of the following code when
4 compiled and run? Select two correct answers.
if((i/=(int)Math.floor(Math.random())) > 1)
System.out.println("No arithmetic
exception");
} catch
(ArithmeticException ae){
System.err.println("Arithmetic
exception caught");
}
}
}
System.out.print(" "+i);
}
}
};
}
}
0 1 2
End
(4) The output cannot be determined
(5) Compilation error
Answer : 1,2
Explanation :
We wait on Thread t1 to finish before printing End
but none of the threads are started so only End is
printed. Moreover, the same output will be printed
whichever the platform is.
#3 What is the output of the following code when
6 compiled and run? Select two correct answers.
System.out.println(getPrimitive(127)); /
/line 1
}
}
public static int getPrimitive(byte b){
//line 2
return (short)
(Math.random()*b); //line 3
}
}
System.out.println("Equal");
else
System.out.println("Not
Equal");
(1) super.oak = 1;
(2) oak = 33;
(3) Base.oak = 22;
(4) oak = 50.1;
Answer : 1,2,3
Explanation :
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.
#4 What will happen when you attempt to
2 compile and run the following code?
void fermin(int i) {
i++;
}
}
(1) System.out.println(i++);
(2) System.out.println(i+'0');
(3) System.out.println(i);
(4) System.out.println(i--);
Answer : 1,3,4
Explanation :
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 outputoperations, 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 ratherthan the
numberical value for 0.
#4 What will happen when you attempt to
4 compile and run this code?
import java.awt.*;
FlowAp() {
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"));
add(new Button("Four"));
}//End of constructor
}//End of Application
class Value
{
public int i = 15;
} //Value
(1) 15 0
20
(2) 15 0
15
(3) 20 0
20
(4) 0 15
20
Answer : 1
Explanation :
When we pass references in Java what actually
gets passed is the value of that reference (i.e.
memory address of the object being referenced
and not the actual object called by that reference)
and it gets passed as value (i.e a copy of
thereference is made). Now when we make
changes to the object referenced by that reference
it reflects on that object even outside of the
method being called but any changes made to the
reference itself is not reflected on that reference
outside ofthe method which is called.
#4 Given the code below, and making no other
9 changes, which access modifiers (public,
protected or private) can legally be placed
before myMethod() on line 3? If line 3 is left
as it is, which keywords can legally be placed
before myMethod on line 8?
1. class HumptyDumpty
2. {
3. void myMethod() {}
4. }
5.
6. class HankyPanky extends HumptyDumpty
7. {
8. void myMethod() {}
9. }
#1 Given:
(1) int x = 6;
(2) short x = 3;
(3) char x = 'y';
(4) long x = 354;
(5) boolean x = true;
Answer : -------------------------
#3 Given:
(1) 2
(2) 4
(3) 6
(4) 7
Answer : -------------------------
#6 Given:
1. class IntType {
2. public String getType(String a, int b, char c) {
3. String holdit1 = new String();
4. holdit1 = a;
5. return holdit1;
6. }
7. }
8.
9. class OverType extends IntType {
10.
11. String holdit2 = new String();
12. holdit2 = holdit2.concat("This is ").concat(a);
13. return holdit2;
14. }
15.
16. public static void main(String args[]) {
17. OverType ot = new OverType();
18. String x = new String("x");
19. int y = 1;
20. char z = 'b';
21. System.out.println(ot.getType(x, y, z));
22. }
23. }
When inserted on line 10, which line will override the getType
method, allowing compilation to succeed and the output "This is
x"?
1. import java.awt.*;
2.
3. public class Birthdays extends Frame {
4. Birthdays() {
5. super("Birthday Reminder");
6. String lblsP1[] = {"Name:", "Birthday:", "Address:"};
7. String butnsP2[] = {"Add", "Save", "Exit"};
8. Panel panelTop = new Panel();
9. Panel panelBot = new Panel();
10. panelTop.setLayout(new GridLayout(3,2,3,3));
11. for(int x = 0; x < lblsP1.length; x++) {
12. panelTop.add(new Label(lblsP1[x]));
13. panelTop.add(new TextField());
14. }
15. for(int y = 0; y < butnsP2.length; y++) {
16. panelBot.add(new Button(butnsP2[y]));
17. }
18. add(panelTop, BorderLayout.NORTH);
19. add(panelBot, BorderLayout.SOUTH);
20. }
21. }
Which main method should you add to the Birthdays class to allow
the program to compile and run with all defined fields properly
displayed?
Given that the Pet class has already been defined, which of the
following fields would be appropriate for inclusion in the Cat class
as members?
Answer : -------------------------
#15 Consider the following classes, declared in separate source files:
What output results when the main method of the class Sub is
run?
(1) Value is 5
Value is 6
(2) This value is 5
This value is 6
(3) Value is 5
This value is 6
(4) This value is 5
Value is 6
(5) I was passed 5
I was passed 6
Answer : -------------------------
#16 Consider the following class definition:
(1) Base() { }
(2) Base(int j) { }
(3) Base(int j, int k) { }
(4) Base(int j, int k, int l) { }
Answer : -------------------------
#18 Which of the following statements are true?
(1) a
(2) b
(3) c
(4) d
(5) e
Answer : -------------------------
#20 Which of the following statements are true?
(1) Given that Inner is a non-static class declared inside a public class
Outer, and appropriate constructor forms are defined, an instance
of Inner may be constructed like this:
new Outer().new Inner()
(2) If an anonymous inner class inside the class Outer is defined to
implement the interface ActionListener, it may be constructed like
this:
new Outer().new ActionListener()
(3) Given that Inner is a non-static class declared inside a public class
Outer and appropriate constructor forms are defined, an instance
of Inner may be constructed in a static method like this:
new Inner()
(4) An anonymous class instance that implements the interface
MyInterface may be constructed and returned from a method like
this: 1. return new MyInterface(int x) { 2. int x; 3. public
MyInterface(int x) { 4. this.x = x; 5. } 6. };
Answer : -------------------------
#21 Given:
class J {
private static int notFinalized;
public static int notFinalized() {return notFinalized;}
private K k;
private int name;
public int name() {return name;}
public J(K k, int i) {this.k = k; name = i; notFinalized++;}
public void finalize() {
synchronized (k) {
System.out.print(name);
notFinalized--;
k.notify();
}
}
}
class K {
private void m1() {
J j = null;
for (int i = 0; i < 5; i++) {
j = new J(this, i); // 1
}
Runtime.getRuntime().gc(); // 2
synchronized (this) {
while (J.notFinalized() > 0) {
try {wait();} catch (InterruptedException ie) {}
}
}
}
public static void main(String[] args) {
new K().m1();
}
}
(1) 0
(2) 1
(3) 4
(4) 5
(5) Can not be determined without more information
(6) Compiler error
(7) Run time error
(8) None of the above
Answer : -------------------------
#22 What is the output of the following code when compiled and run?
Select two correct answers
(1) Prints 3
(2) Error during compilation at line 4
(3) Error during compilation at line 5
(4) Prints 11
(5) Prints 0
Answer : -------------------------
#24 Select three correct statements:
(1) The garbage collection thread cannot outlive the last user thread
(2) The garbage collection can be forced by invoking System.gc().
(3) The garbage collection thread is a non-deamon thread
(4) The finalize() method is invoked at most once by the JVM for any
given object
(5) The finalize() method may resurrect the object upon which it has
been invoked
Answer : -------------------------
#25 What is the output of the following code when compiled and run?
Select one correct answer.
import java.io.*;
public class TechnoSample {
public static void main(String[] args) {
TechnoSampleSub myref = new
TechnoSampleSub();
try{
myref.test();
}catch(IOException ioe){}
}
void test() throws IOException{
System.out.println("In TechnoSample");
throw new IOException();
}
}
class TechnoSampleSub extends TechnoSample {
void test() {
System.out.println("In TechnoSampleSub");
}
}
(1) Prints:
In TechnoSampleSub
(2) Prints:
In TechnoSample
(3) Prints:
In TechnoSample
In TechnoSampleSub
(4) Prints:
In TechnoSampleSub
In TechnoSample
(5) The code does not compile
Answer : -------------------------
#26 What is the output of the following code when compiled and run
with the following command line: java TechnoSample two three?
Select two correct answers.
class A{}
class B extends A implements E{} //line 1
class C extends A{}
class D extends B{}
interface E{}
public class Question07 {
public static void main(String[] args) {
A a = new D(); //line 2
C c = new C(); //line 3
E e = (E)a; //line 4
B b = (B)e; //line 5
}
}
(1) 0
(2) 1
(3) 2
(4) 3
(5) 4
Answer : -------------------------
#29 What is the output of the following code when compiled and run?
Select one correct answer.
(1) Prints 0 1 2 3 4
(2) Compilation error
(3) No output
(4) IllegalThreadStateException is thrown at runtime
(5) Prints 0 1 2 3 4 5
Answer : -------------------------
#31 What is the output of the following code when compiled and run?
Select one correct answer.
(1) Prints
Hello World
Hello World
(2) Prints
Hello orld
Hello orld
(3) Prints
Hello orld
ello orld
(4) Prints
ello orld
ello orld
(5) Compilation error
Answer : -------------------------
#32 What is the output of the following code when compiled and run?
Select two correct answers. (Note: when an instance of a Vector is
printed, its content appear between square brackets [])
import java.util.*;
public class TechnoSample {
public static void main(String[] args) {
Vector col = new Vector();
col.add(new Integer(1));
col.add(new Integer("2"));
col.add(new Float(3.2d)); //line 1
col.add(col.elementAt(1));
col.setElementAt(col.elementAt(2),0);
System.out.println(col);
}
}
(1) Prints:
Hello
World!
(2) Prints Hello World!(linefeed is ignored)
(3) Compilation error
(4) Compiles fine, but an exception is thrown at runtime
(5) Unicode characters like '\u0048' may be used to create String
literals
Answer : -------------------------
#34 What is the output of the following code when compiled and run?
Select two correct answers.
(1) The output will always be the same whatever the underlying
platform is
(2) Prints: End
(3) Prints:
0 1 2
End
(4) The output cannot be determined
(5) Compilation error
Answer : -------------------------
#36 What is the output of the following code when compiled and run?
Select two correct answers.
import java.util.Date;
public class Example {
public static void main(String args[]) {
Date d1 = new Date (99, 11, 31);
Date d2 = new Date (99, 11, 31);
method(d1, d2);
System.out.println("d1 is " + d1
+ "\nd2 is " + d2);
}
if("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
(1) super.oak = 1;
(2) oak = 33;
(3) Base.oak = 22;
(4) oak = 50.1;
Answer : -------------------------
#42 What will happen when you attempt to compile and run the
following code?
void fermin(int i) {
i++;
}
}
Which of the following lines if placed after the comment //Here will
print out 0.
(1) System.out.println(i++);
(2) System.out.println(i+'0');
(3) System.out.println(i);
(4) System.out.println(i--);
Answer : -------------------------
#44 What will happen when you attempt to compile and run this code?
import java.awt.*;
FlowAp() {
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"));
add(new Button("Four"));
}//End of constructor
}//End of Application
(1) A Frame with buttons marked One to Four placed on each edge
(2) A Frame with buutons marked One to four running from the top to
bottom
(3) A Frame with one large button marked Four in the Centre
(4) An Error at run time indicating you have not set a LayoutManager
Answer : -------------------------
#46 What will happen when you attempt to compile and run the
following code?
(1) A compile time error indicating that no run method is defined for
the Thread class
(2) A run time error indicating that no run method is defined for the
Thread class
(3) Clean compile and at run time the values 0 to 9 are printed out
(4) Clean compile but no output at runtime
Answer : -------------------------
#47
int Output = 10;
boolean b1 = false;
class Value
{
public int i = 15;
} //Value
(1) 15 0
20
(2) 15 0
15
(3) 20 0
20
(4) 0 15
20
Answer : -------------------------
#49 Given the code below, and making no other changes, which access
modifiers (public, protected or private) can legally be placed before
myMethod() on line 3? If line 3 is left as it is, which keywords can
legally be placed before myMethod on line 8?
1. class HumptyDumpty
2. {
3. void myMethod() {}
4. }
5.
6. class HankyPanky extends HumptyDumpty
7. {
8. void myMethod() {}
9. }