• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

SCJP 1.4 Mock Exam – 14

































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































1

Given Answer class behaves like some
a File it has a Vector , a color, some boolean variable?


import
public
private
Vector
Serializable
File
Color
extends
boolean
implements




What is the correct declaration?










Answer :
————————-






2

Some design issues: The following
description applies to a class: given someclassname behaves as
somesuperclassname and it has some fields etc it is accessed in other
files. No other class can behave as this class.

  
extends
public
int
class
someclassname
somesuperclass
implements
File
extends
Class
final




What is the right syntax declaration of this class (without {)?










Answer :
————————-






3

Which of the following is correct?
Select the two correct answers.





(1)

The native keyword indicates that
the method is implemented in another language like C/C++


(2)

The only statements that can appear
before an import statement in a Java file are comments


(3)

The method definitions inside
interfaces are public and abstract. They cannot be private or
protected


(4)

A class constructor may have public
or protected keyword before them, nothing else







Answer :
————————-






4

What is the result of compiling and
running the following program.


public class test {
public static void main(String args[]) {
String str1=”abc”;
String str2=”def”;
String str3=str1.concat(str2);

str1.concat(str2);
System.out.println(str1);
}
}












(1)

abc

(2)

def

(3)

abcabc

(4)

abcdef

(5)

defabc

(6)

abcdefdef






Answer :
————————-






5

What is the result of compiling and
running the following program. Select the one correct answer.


class test {
public static void main(String args[]) {
char ch;
String test2 = “abcd”;
String test = new String(“abcd”);
if(test.equals(test2)) {
if(test == test2)
ch = test.charAt(0);
else
ch = test.charAt(1);
}
else {
if(test == test2)
ch = test.charAt(2);
else
ch = test.charAt(3);
}
System.out.println(ch);
}
}








(1)

‘a’

(2)

‘b’

(3)

‘c’

(4)

‘d’






Answer :
————————-






6

To make a variable defined in a
class accessible only to methods defined in the classes in same package,
which of the following keyword should be used. Select the one correct
answer





(1)

By using the keyword package before
the variable


(2)

By using the keyword private before
the variable


(3)

By using the keyword protected
before the variable


(4)

By using the keyword public before
the variable


(5)

The variable should not be preceded
by any of the above mentioned keywords







Answer :
————————-






7

Which Listener interface must be
implemented by a class responsible for handling mouse clicks on buttons?










Answer :
————————-






8

Which of the following will output
-4.0





(1)

System.out.println(Math.floor(-4.7));

(2)

System.out.println(Math.round(-4.7));

(3)

System.out.println(Math.ceil(-4.7));

(4)

System.out.println(Math.Min(-4.7));






Answer :
————————-






9

What is the result of the following
operation?

System.out.println(4 | 3);












(1)

6

(2)

0

(3)

1

(4)

7






Answer :
————————-






10

What will happen when you attempt to
compile and run the following code?


class Background implements Runnable {
int i=0;

public int run() {
while(true) {
i++;
System.out.println(“i=”+i);
}
}
}








(1)

It will compile and the run method
will print out the increasing value of i


(2)

It will compile and calling start
will print out the increasing value of i


(3)

The code will cause an error at
compile time


(4)

Compilation will cause an error
because while cannot take a parameter of true







Answer :
————————-






11

What will the following code print
out?


public class TechnoSample {
public static void main(String argv[]) {
TechnoSample sample = new TechnoSample();
sample.amethod();
}

public void amethod() {
int oi= 012;
System.out.println(oi);
}
} // Oct



(1)

12

(2)

012

(3)

10

(4)

10.0






Answer :
————————-






12

You need to create a class that will
store a unique object elements. You do not need to sort these elements but
they must be unique.



What interface might be most suitable to meet this need?





(1)

Set

(2)

List

(3)

Map

(4)

Vector






Answer :
————————-






13

You are concerned about that your
program may attempt to use more memory than is available. To avoid this
situation you want to ensure that the Java Virtual Machine will run its
garbage collection just before you start a complex routine. What can you
do to be certain that garbage collection will run when you want.





(1)

You cannot be certain when garbage
collection will run


(2)

Use the Runtime.gc() method to force
garbage collection


(3)

Ensure that all the variables you
require to be garbage collected are set to null


(4)

Use the System.gc() method to force
garbage collection







Answer :
————————-






14

Which of the following most closely
describes a bitset collection?





(1)

A class that contains groups of
unique sequences of bits


(2)

A method for flipping individual
bits in instance of a primitive type


(3)

An array of boolean primitives that
indicate zeros or ones


(4)

A collection for storing bits as
on-off information, like a vector of bits







Answer :
————————-






15

You have these files in the same
directory. What will happen when you attempt to compile and run
Class1.java if you have not already compiled Base.java


//Base.java
package Base;

class Base {
protected void amethod() {
System.out.println(“amethod”);
}
} // Base

package Class1;

public class Class1 extends Base {
public static void main(String argv[]) {
Base b = new Base();
b.amethod();
}
} // Class1



(1)

Compile Error: Methods in Base not
found


(2)

Compile Error: Unable to access
protected method in base class


(3)

Compilation followed by the output
“amethod”


(4)

Compile error: Superclass
Class1.Base of class Class1.Class1 not found







Answer :
————————-






16

Given:

class TechnoSample {
public static void main(String args[]) {
short[] s = {1, -1, 3, 4};
for (int i = 0; i
switch(s[i]) {
case 2-1: System.out.print(“v “);
break;
case ‘d’-‘a’: System.out.print(“w “);
break;
case 0: System.out.print(“x “);
break;
case ~0: System.out.print(“y “);
break;
case 4&5: System.out.print(“z “);
break;
default: System.out.print(“Default “);
}
}
}
}




What is the result of attempting to compile and run the above program?





(1)

Prints: v w x y

(2)

Prints: v w x y z Default

(3)

Prints: v y w z

(4)

Prints: Default Default Default
Default


(5)

Runtime Exception

(6)

Compiler Error

(7)

None of the Above






Answer :
————————-






17

Given:

class TechnoSample {
public static void main (String args[]) {
int i = 0;
int j = 0;
label1:
while (i++<5) {
label2:
for (;;) {
label3:
do {
System.out.print(i + j);
switch (i+j++) {
case 0: continue label3;
case 1: continue label2;
case 2: continue label1;
case 3: break;
case 4: break label3;
case 5: break label2;
case 6: break label1;
default: break label1;
}
} while (++j<5);
}
}
}
}




What is the result of attempting to compile and run the above program?





(1)

Prints: 12457

(2)

Prints: 02357

(3)

Prints: 02356

(4)

Prints: 1357

(5)

Prints: 1356

(6)

Runtime Exception

(7)

Compiler Error

(8)

None of the Above






Answer :
————————-






18


1. class A {
2. void m1() {throw new ArithmeticException();}
3. void m2() {throw new ClassCastException();}
4. void m3() {throw new IllegalArgumentException();}
5. void m4() {throw new IndexOutOfBoundsException();}
6. void m5() {throw new NullPointerException();}
7. void m6() {throw new SecurityException();}
8. }




What is the result of attempting to compile the program?





(1)

Compiler error at line 2

(2)

Compiler error at line 3

(3)

Compiler error at line 4

(4)

Compiler error at line 5

(5)

Compiler error at line 6

(6)

Compiler error at line 7

(7)

None of the Above






Answer :
————————-






19


class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}

class Purple {
public static void main(String args[]) {
int a,b,c,d,f,g,x;
a = b = c = d = f = g = 0;
x = 3;
try {
try {
switch (x) {
case 1: throw new Level1Exception();
case 2: throw new Level2Exception();
case 3: throw new Level3Exception();
}
a++;
}
catch (Level2Exception e) {b++;}
finally{c++;}
}
catch (Level1Exception e) { d++;}
catch (Exception e) {f++;}
finally {g++;}
System.out.print(a+”,”+b+”,”+c+”,”+d+”,”+f+”,”+g);
}
}




What is the result of attempting to compile and run the program?





(1)

Prints: 1,1,1,0,0,1

(2)

Prints: 0,1,1,0,0,1

(3)

Prints: 0,1,0,0,0,0

(4)

Prints: 0,1,0,0,0,1

(5)

Prints: 0,0,1,0,0,1

(6)

Compiler Error

(7)

Run Time Error

(8)

None of the Above






Answer :
————————-






20


class A {

public static void main (String args[]) {
int h = 0, i = 0, j = 0, k = 0;

label1:
for (;;) {
h++;

label2:
do {
i++;
k = h + i + j;

switch (k) {
default: break label1;
case 1: continue label1;
case 2: break;
case 3: break label2;
case 4: continue label2;
case 5: continue label1;
}
} while (++j<5);
}
System.out.println(h + “,” + i + “,” + j);
}
}




What is the result of attempting to compile and run the above program?





(1)

Prints: 1,2,3

(2)

Prints: 1,3,2

(3)

Prints: 2,2,2

(4)

Prints: 2,4,1

(5)

Prints: 2,4,2

(6)

Runtime Exception

(7)

Compiler Error

(8)

None of the Above






Answer :
————————-






21

Which of the follow are true
statements.





(1)

A nested class is any class that is
declared within the body of another class or interface


(2)

A nested class can not be declared
within the body of an interface declaration


(3)

A top level class is a class this is
not a nested class


(4)

An inner class is a nested class
that is not static


(5)

A nested class can not be declared
static


(6)

A named class is any class that is
not anonymous


(7)

None of the above






Answer :
————————-






22

The only access control modifiers
supported by Java are:


public
protected
private








(1)

True

(2)

False






Answer :
————————-






23

Which of the following are True?





(1)

() is a unary operator

(2)

() is a function operator

(3)

int x = 10 + +11; is a invalid
statment


(4)

int x = (char)(int)(10); will give
compiler error







Answer :
————————-






24

Which of the following statements
are False?





(1)

Checked exceptions can not be caught
using catch() in the same function


(2)

New exception can be thrown with in
a catch block


(3)

No exception can be thrown from a
finally block


(4)

for loop executes its block
statments atleast once


(5)

Unhandled exceptions are handled by
JVM and the program will coninue







Answer :
————————-






25

What will happen if you compile/run
this code?


1: public class Q1 extends Thread
2: {
3: public void run()
4: {
5: System.out.println(“Before start method”);
6: this.stop();
7: System.out.println(“After stop method”);
8: }
9:
10: public static void main(String[] args)
11: {
12: Q1 a = new Q1();
13: a.start();
14: }
15: }








(1)

Compilation error at line 7

(2)

Runtime exception at line 7

(3)

Prints “Before start method” and
“After stop method”


(4)

Prints “Before start method”
only







Answer :
————————-






26

The following code will give:

1 class Test
2 {
3 void show()
4 {
5 System.out.println(“non-static method in Test”);
6 }
7 }
8 public class Q3 extends Test
9 {
10 static void show()
11 {
12 System.out.println(“Overridden non-static method in Q3”);
13 }
14
15 public static void main(String[] args)
16 {
17 Q3 a = new Q3();
18 }
19 }








(1)

Compilation error at line 3

(2)

Compilation error at line 10

(3)

No compilation error, but runtime
exception at line 3


(4)

No compilation error, but runtime
exception at line 10







Answer :
————————-






27

The following code will
print:


1 if( new Boolean(“true”) == new Boolean(“true”))
2 System.out.println(“True”);
3 else
4 System.out.println(“False”);








(1)

Compilation error

(2)

No compilation error, but runtime
exception


(3)

Prints “True”

(4)

Prints “False”






Answer :
————————-






28

Which of the following statements
are True?





(1)

Constructors cannot have a
visibility modifier


(2)

Constructors can be marked public
and protected, but not private


(3)

Constructors can only have a
primitive return type


(4)

Constructors are not
inherited







Answer :
————————-






29

Which of the following will compile
without error?





(1)

char c=’1′;

System.out.println(c>>1);


(2)

Integer i=Integer(“1”);

System.out.println(i>>1);


(3)

int i=1;

System.out.println(i<<<1);


(4)

int i=1;

System.out.println(i<<1);







Answer :
————————-






30

You are given a class hierarchy with
an instance of the class Dog. The class Dog is a child of mammal and the
class Mammal is a child of the class Vertebrate. The class Vertebrate has
a method called move which prints out the string “move”. The class mammal
overrides this method and prints out the string “walks”. The class Dog
overrides this method and prints out the string “walks on paws”. Given an
instance of the class Dog,. how can you access the ancestor method move in
Vertebrate so it prints out the string “move”;





(1)

d.super().super().move();

(2)

d.parent().parent().move();

(3)

d.move();

(4)

none of the above






Answer :
————————-






31

Which of the following statements
are True?





(1)

An inner class may be defined as
static


(2)

There are NO circumstances where an
inner class may be defined as private


(3)

A programmer may only provide one
constructor for an anonymous class


(4)

An inner class may extend another
class







Answer :
————————-






32

Under what circumstances might you
use the yield method of the Thread class





(1)

To call from the currently running
thread to allow another thread of the same or higher priority to
run


(2)

To call on a waiting thread to allow
it to run


(3)

To allow a thread of higher priority
to run


(4)

To call from the currently running
thread with a parameter designating which thread should be allowed to
run







Answer :
————————-






33

What will be the result when you
attempt to compile this program?


public class Rand {
public static void main(String argv[]) {
int iRand;
iRand = Math.random();
System.out.println(iRand);
}
} // Rand



(1)

Compile time error referring to a
cast problem


(2)

A random number between 1 and
10


(3)

A random number between 0 and
1


(4)

A compile time error about random
being an unrecognised method







Answer :
————————-






34

It is possible for two classes to be
the super class of each other. True Or False?





(1)

True

(2)

False






Answer :
————————-






35

Given classes A, B & C where B
extends A and C extends B, and where all classes implement the instance
method ‘void print()’. How can the print() method in A be called from an
instance method in C?



Select one right answer.





(1)

print();

(2)

super.print();

(3)

super.super.print();

(4)

this.super.print();

(5)

A.this.print();

(6)

((A)this).print();

(7)

It is not possible






Answer :
————————-






36

Which of these statements are valid
when occuring by themselves?



Select all valid answers.





(1)

while() break;

(2)

do { break; } while (true);

(3)

if (true) { break; }

(4)

switch (1) { default: break;
}


(5)

for (;true;) break;






Answer :
————————-






37

All public methods in the Thread
class are static and therefore only affect the current thread. True Or
False?





(1)

True

(2)

False






Answer :
————————-






38

Which of the following statements
regarding threads are true?



Select all valid statements.





(1)

void run(void) method is one of the
methods in the Runnable interface


(2)

yield() causes the current thread to
move into the ready state


(3)

some of the public methods in the
Thread class are static


(4)

notify() takes one argument, the
object to which it needs to notify and notifyAll() takes no
arguments


(5)

every object has a lock which
controls which thread has access to the objects synchronized code


(6)

wait, notify & notifyAll methods
must always be called from inside synchronized code


(7)

wait, notify & notifyAll methods
are part of Thread class only







Answer :
————————-






39

The following code will
print:


1: Double a = new Double(Double.NaN);
2: Double b = new Double(Double.NaN);
3:
4: if( Double.NaN == Double.NaN )
5: System.out.println(“True”);
6: else
7: System.out.println(“False”);
8:
9: if( a.equals(b) )
10: System.out.println(“True”);
11: else
12: System.out.println(“False”);








(1)

True

True


(2)

True

False


(3)

False

True


(4)

False

False







Answer :
————————-






40

What will happen if you compile/run
the following code?


1 public class Q11
2 {
3 static String str1 = “main method with String[] args”;
4 static String str2 = “main method with int[] args”;
5
6 public static void main(String[] args)
7 {
8 System.out.println(str1);
9 }
10
11 public static void main(int[] args)
12 {
13 System.out.println(str2);
14 }
15 }








(1)

Duplicate method main(), compilation
error at line 6


(2)

Duplicate method main(), compilation
error at line 11


(3)

Prints “main method with main
String[] args”


(4)

Prints “main method with main int[] args”






Answer :
————————-






41

What is the output of the following
code?


1 int i = 16;
2 int j = 17;
3
4 System.out.println(“i >> 1 = ” + (i >> 1));
5 System.out.println(“j >> 1 = ” + (j >> 1));








(1)

Prints i >> 1 = 8

j >> 1 = 8


(2)

Prints i >> 1 = 7

j >> 1 = 7


(3)

Prints i >> 1 = 8

j >> 1 = 9


(4)

Prints i >> 1 = 7

j >> 1 = 8







Answer :
————————-






42

What is the output of the following
code?


1 int i = 45678;
2 int j = ~i;
3
4 System.out.println(j);










(1)

Compilation error at line 2. ~
operator applicable to boolean values only


(2)

Prints 45677

(3)

Prints -45677

(4)

Prints -45679






Answer :
————————-






43

What will happen when you invoke the
following method?


1 void infiniteLoop()
2 {
3 byte b = 1;
4
5 while ( ++b > 0 )
6 ;
7 System.out.println(“Welcome to Java”);
8 }










(1)

The loop never
ends(infiniteLoop)


(2)

Prints “Welcome to Java”

(3)

Compilation error at line 5. ++
operator should not be used for byte type variables


(4)

Prints nothing






Answer :
————————-






44

Which of the following are
syntactically correct?





(1)

String[] sa1,sa2;

(2)

Integer iwSize[] = new Integer[]{new
Integer(1)};


(3)

short s[] = new short[10];

(4)

int i[10];






Answer :
————————-






45

Given the following code, which
statement is true?


class A {}
class B extends A {}

public class C
{
public static void main(String[] args)
{
A[] arrA;
B[] arrB;

arrA = new A[10];
arrB = new B[20];

arrA = arrB; // (1)
arrB = (B[]) arrA; // (2)

arrA = new A[10];
arrB = (B[]) arrA; // (3)
}
}




Select one right answer.





(1)

The code will fail to compile owing
to the line labeled (1)


(2)

The code will throw a
java.lang.ClassCastException at the line labelel (2), when run


(3)

The code will throw a
java.lang.ClassCastException at the line labelel (3), when run


(4)

The code will compile and run
without problems, even if the (B[]) cast in the lines labeled (2) &
(3) were removed


(5)

The code will compile and run
without problems, but would not do so if the (B[]) cast in the lines (2)
& (3) were removed







Answer :
————————-






46

Given the following code

public class Boxes{
String sValue;

Boxes(String sValue){
this.sValue=sValue;
}

public String getValue(){
return sValue;
}

public boolean equals(Object o){
String s = (String) o;
if (sValue.equals(s) ){
return true;
}else{
return false;
}


}

public int hashCode(){
return sValue.hashCode();

}
}




Which of the following statements are true?





(1)

The hashCode method is correctly
implemented


(2)

This class will not compile as
String has no hashCode method


(3)

The hashCode method is not
icorrectly implemented


(4)

This class will not compile because
the compareTo method is not implemented







Answer :
————————-






47

Which of the following are methods
of the Collection interface?





(1)

iterator

(2)

isEmpty

(3)

toArray

(4)

setText






Answer :
————————-






48

What can cause a thread to stop
executing?





(1)

The program exits via a call to
System.exit(0);


(2)

Another thread is given a higher
priority


(3)

A call to the thread’s stop
method


(4)

A call to the halt method of the
Thread class







Answer :
————————-






49

Given:

public class TechnoExample
{
int xyz = 22;
…

public void static main(String junkArgs[])
{
…
}
}




While one of the following statements is true? Select one correct
answer.





(1)

this.xyz is accessible from the main
method with any access specifier for xyz


(2)

this.xyz is accessible from the main
method if the declaration of xyz is private


(3)

this.xyz is accessible from the main
method if the declaration of xyz is public


(4)

This.xyz is accessible from the main
method without any changes to the existing code







Answer :
————————-






50

Which of the following statements
are true?





(1)

Creating a Thread using the Runnable
interface does not require direct access to the Thread class


(2)

Using the Thread class does not
require any additional import statements


(3)

yield is a static method of the
Thread class


(4)

yield is a static method of the
Object class







Answer :
————————-






 

 




 



1] public class Answer extends File implements
Serializable



Explanation:







* * * *






2] public final class someclassname extends somesuperclassname



Explanation:







* * * *






3] 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.





* * * *






4] 1



Explanation:

Not available





* * * *






5] 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.





* * * *






6] 5



Explanation:

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





* * * *






7] ActionListener



Explanation:







* * * *






8] 3



Explanation:

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





* * * *






9] 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.





* * * *






10] 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();








* * * *






11] 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.





* * * *






12] 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.





* * * *






13] 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.





* * * *






14] 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.





* * * *






15] 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.





* * * *






16] 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.





* * * *






17] 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.





* * * *






18] 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.





* * * *






19] 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.





* * * *






20] 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.





* * * *






21] 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.





* * * *






22] 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.





* * * *






23] 1



Explanation:







* * * *






24] 1,3,4,5



Explanation:

No explanation available





* * * *






25] 4



Explanation:

After the execution of stop() method, thread won’t execute any more
statements.





* * * *






26] 2



Explanation:

You can’t override an non-static method with static method.





* * * *






27] 4



Explanation:

No explanation available





* * * *






28] 4



Explanation:

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





* * * *






29] 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.





* * * *






30] 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.





* * * *






31] 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.





* * * *






32] 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.





* * * *






33] 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.





* * * *






34] 2



Explanation:

Please see the Java Language Specification





* * * *






35] 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.





* * * *






36] 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.





* * * *






37] 1



Explanation:

Please see Java Language Specification.





* * * *






38] 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.





* * * *






39] 3



Explanation:

Please see the Java Language Specification.





* * * *






40] 3



Explanation:

Here the main method was just overloaded, so it won’t give any compilation
error.





* * * *






41] 1



Explanation:

16 >> 1 is 8 and 17 >> 1 also 8.





* * * *






42] 4



Explanation:

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





* * * *






43] 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”.





* * * *






44] 1,2,3



Explanation:

(From Marcus Green’s Question of the day)





* * * *






45] 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[].





* * * *






46] 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.





* * * *






47] 1,2,3



Explanation:

No explanation available.





* * * *






48] 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.





* * * *






49] 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.





* * * *






50] 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.


Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact