hello friend's,
will you please help me in solving these questions,
I need these answers urgent but have poor knowledge of
java programming...
please help me out.
1. Select all correct declarations, or declaration and initializations of an
array?
A)
String str[];
B) String str[5] = new String[5];
C) String str[]=new String [] {"string1", "string 2", "string3", "string4",
"string5"};
D) String str[]= {"string1","string2", "string3", "string4", "string5"};
2. Which of the following are the java keywords?
A) final B) Abstract
C) Long D) static
3. The synchronized is used in which of the following?
A) Class declarations. B) Method declarations.
C) Block of code declarations D) Variable declarations.
4. What will be printed when you execute the code?
class A {
A() {
System.out.println("Class A Constructor");
}
}
public class B extends A {
B() {
System.out.println("Class B Constructor");
}
public static void main(String args[]) {
B b = new B();
}
}
A) "Class A Constructor" followed by "Class B Constructor"
B) "Class B Constructor" followed by "Class A Constructor"
C) Compile time error
D) Run time error
5. Given the piece of code, select the correct to replace at the comment line?
class A {
A(int i) { }
}
public class B extends A {
B() {
// xxxxx
}
public static void main(String args[]) {
B b = new B();
}
}
A) super(100); B) this(100);
C) super(); D) this();
6. Which of the statements are true?
A) Overridden methods have the same method name and signature
B) Overloaded methods have the same method name and signature
C) Overridden methods have the same method name and different signature
D) Overloaded methods have the same method name and different signature
7. What is the output when you execute the following code?
int i = 100;
switch (i) {
case 100:
System.out.println(i);
case 200:
System.out.println(i);
case 300:
System.out.println(i);
}
A) Nothing is printed B) Compile time error
C) The values 100,100,100 printed D) Only 100 is printed
8. How can you change the break statement below so that it breaks out of the
inner and middle loops and continues with the next iteration of the outer loop?
outer: for ( int x =0; x < 3; x++ ) {
middle: for ( int y=0; y < 3; y++ ) {
if ( y == 1) {
break;
}
}
}
A) break inner: B) break middle:
C) break outer: D) continue
E) continue middle
9. What is the result of compiling the following code?
import java.io.*;
class MyExp {
void MyMethod() throws IOException, EOFException {
//............//
}
}
class MyExp1 extends MyExp {
void MyMethod() {
//..........//
}
}
public class MyExp2 extends MyExp1 {
void MyMethod() throws IOException {
//.........//
}
}
A) Compile time error B) No compile time error
C) Run-Time error
D) MyMethod() cannot throw an exception in MyExp2 class
10. What is the result when you compile the and run the following code?
public class ThrowsDemo {
static void throwMethod() {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
A) Compilation error B) Runtime error
C) Compile successfully, nothing is printed.
D) inside demoMethod. followed by caught: java.lang.IllegalAccessExcption: demo
11. Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object.
D) Garbage collector immediately runs when you set the references to null.
12. From the following code how many objects are garbage collected?
String string1 = "Test";
String string2 = "Today";
string1 = null;
string1 = string2;
A) 1 B) 2
C) 3 D) 0
13. Select all correct list of keywords?
A) superclass B) goto
C) open D) integer
E) import, package F) They are all java keywords
14. Select the correct form for anonymous inner class declaration ?
A) new Outer.new Inner B) new Inner() {
C) new Inner() D) Outer.new Inner()
15. Which of the following statements are true?
A) An anonymous class cannot have any constructors
B) An anonymous class can only be created within the body of a method
C) An anonymous class can only access static fields of the enclosing class
D) An anonymous class instantiated and declared in the same place.
16. Which of the following class definitions are legal declaration of an
abstract class?
A) class A { abstract void Method() {} }
B) abstract class A { abstract void Method() ; }
C) class A { abstract void Method() {System.out.println("Test");} }
D) class abstract A { abstract void Method() {} }
17. What is the result of compiling the following code?
public class
Test {
public static void main ( String[] args) {
int value;
value = value + 1;
System.out.println(" The value is : " + value);
}
}
A) Compile and runs with no output
B) Compiles and runs printing out "The value is 1"
C) Does not compile
D) Compiles but generates run time error
18. What is the result of compiling the following code? When you run like given
below?
java Test Hello How Are You
public class Test {
public static void main ( String[] args) {
for ( int i = 0; i < args.length; i++)
System.out.print(args[i]);
}
}
A) Compile and runs with no output
B) Compiles and runs printing out "HelloHowAreYou"
C) Does not compile
D) Compiles but generates run time error
19. Which are the following are java keywords?
A) goto B) synchronized
C) extends D) implements
E) this F) NULL
20. What is the output of the following code?
public class TestLocal {
public static void main(String args[]) {
String s[] = new String[6];
System.out.print(s[6]);
}
}
A) A null is printed B) Compile time error
C) Exception is thrown D) null followed by 0 is printed on the screen
21. Which of the following assignment statements is invalid?
A) long l = 698.65; B) float f = 55.8;
C) double d = 0x45876; D) All of the above
22. What is the numeric range for a Java int data type?
A) 0 to (2^32) B) -(2^31) to (2^31)
C) -(2^31) to (2^31 - 1) D) -(2^15) to (2^15 - 1)
23. Which of the following method returns the ID of an event?
A) int getID() B) String getSource()
C) int returnID() D) int eventID()
24. Which of the following are correct, if you compile the following code?
public class CloseWindow extends Frame implements WindowListener {
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public static void main(String args[]) {
CloseWindow CW = new CloseWindow();
}
}
A) Compile time error B) Run time error
C) Code compiles but Frames does not listen to WindowEvents
D) Compile and runs successfully.
25. What is correct about event handling in Java?
A) Java 1.0 event handling is compatible with event delegation model in Java
1.1
B) Java 1.0 and Java 1.1 event handling models are not compatible
C) Event listeners are the objects that implements listener interfaces.
D) You can add multiple listeners to any event source, then there is no
guarantee that the listeners will be notified in the order in which they were
added.
26. Given the byte with a value of 01110111, which of the following statements
will produce 00111011?
A) 0x77 << 1; B) 0x77 >>> 1;
C) 0x77 >> 1; D) None of the above
27. Which of the following will compile without error?
A) char c = 'a'; B) double d = 45.6;
C) int i = d; D) int k = 8;
28. Which of the following returns true when replace with XXXXXXXXX?
public class TestType {
public static void main(String args[] ) {
Button b = new Button("BUTTON");
if( XXXXXXXXX) {
System.out.print("This is an instance of Button");
}
}
}
A) b instanceof Button B) Button instanceof b
C) b == Button D) Button == (Object) b
29. The statement X %= 5, can best described as?
A) A equals a divided by 5; B) A equals A in 5 digit percentage form
C) A equals A modulus 5. D) None of the above
30. What will happen when you attempt to compile and run the following code?
public class MyClass {
public static void main(String args[]) {
String s1 = new String("Test One");
String s2 = new String("Test One");
if ( s1== s2 ) {
System.out.println("Both are equal");
}
Boolean b = new Boolean(true);
Boolean b1 = new Boolean(false);
if ( b.equals(b1) ) {
System.out.println("These wrappers are equal");
}
}
}
A) Compile time error B) Runtime error.
C) No output D) "These wrappers are equal"