0% found this document useful (0 votes)
201 views

Correct File

The code defines a class called Ombersley with a main method that declares a boolean variable b1 and initializes it to true. It then calls a static method place(), passing b1 as a parameter. The place() method prints "Borcetshire" if the parameter is true, then prints "Powick" and returns true. When run, the code will output "Hello Crowle" since the if statement in main() evaluates to true.

Uploaded by

kumargaurav_29
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
201 views

Correct File

The code defines a class called Ombersley with a main method that declares a boolean variable b1 and initializes it to true. It then calls a static method place(), passing b1 as a parameter. The place() method prints "Borcetshire" if the parameter is true, then prints "Powick" and returns true. When run, the code will output "Hello Crowle" since the if statement in main() evaluates to true.

Uploaded by

kumargaurav_29
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Given the following class<br> public class Ombersley{<br> public static void main(String argv[]){<br> boolean b1 = true;<br> if((b1

==true) place(true)){<br> System.out.println("Hello Crowle");<br> }<br> }<br> public static boolean place(boolean location){<br> if(location==true){<br> System.out.println("Borcetshire");<br> }<br> System.out.println("Powick");<br> return true;<br> }<br> }<br> What will happen when you attempt to compile and run it? A. Compile time error B. Output of "Hello Crowle" C. Output of Borcetshire and Powick followed by "Hello Crowle" D. No output ANSWER: B Which of the following statements are true? A. The % is used to calculate a percentage thus: 10 % 20=50 B. The / operator is used to divide one value by another C. The # symbol may be used as the first character of a variable D. The $ symbol may not be used as the first character of a variable ANSWER: B Which interface is used to create new thread? A. Throwable B. Thread C. Runnable D. Object ANSWER: C Which of the following best describes the use of the synchronized keyword? A. Allows two process to run in paralell but to communicate with each other B. Ensures only one thread at a time may access a method or object C. Ensures that two or more processes will start and end at the same time D. Ensures that two or more Threads will start and end at the same time ANSWER: B

What will happen when you attempt to compile and run the following code?<br> public class Inc{<br> public static void main(String argv[]){<br> Inc inc = new Inc();<br> int i =0; <br> inc.fermin(i);<br> int a = i++;<br> System.out.println(a);<br> }<br> void fermin(int i){<br> i++;<br> }<br> }<br> A. Output of 0

B. C. D. ANSWER:

Output of 2 Output of 1 Compile time error A

Given the following class public class ZeroPrint{<br> public static void main(String argv[]){<br> int i =0;<br> //Here <br> }<br> }<br> Which of the following lines if placed after the comment //Here will print out 0 . A. System.out.println(++i); B. System.out.println(i+'0'); C. System.out.println(i); D. System.out.println(--i); ANSWER: C Given:<br> import java.util.*;<br> public class Example {<br> public static void main(String[] args) {<br> // insert code XXXXXXX here<br> set.add(new integer(2));<br> set.add(new integer(l));<br> System.out.println(set);<br> }<br> }<br> Which code, inserted at line 4, guarantees that this program will<br> output [1, 2]?<br> A. List set = new SortedList(); B. Set set = new HashSet(); C. Set set = new SortedSet(); D. Set set = new TreeSet(); ANSWER: D class DangerSet<br> {<br> public static void main(String arg[]) {<br> java.util.Set set = new java.util.HashSet();<br> set.add("Danger");<br> if(set.add("Danger"))<br> System.out.println("addition ok");<br> else<br> System.out.println("addition fail");<br> }<br> }<br> A. addtion ok B. addition fail C. Danger D. compile time or runtime error ANSWER: B public class Inc implements Runnable {<br> public void run()<br> {<br>

Thread tt = new Thread(this);<br> tt.start();<br> System.out.println("Hello");<br> }<br> public static void main(String[] args) {<br> Thread t = new Thread(new Inc());<br> t.start(); <br> }<br> } A compiler error B Hello C Hello - infinite times D. Run time error ANSWER: C class Q0{<br> int i;<br> Q0(int i){<br> System.out.print(i);<br> this.i = i;<br> }<br> public static void main(String ka[]){<br> Q0 obj = new Q0(10);<br> System.out.print(obj.i);<br> }<br> A. B. C. D. ANSWER: }<br> 1010 Compile error :Variable i may not have been initialized. 010 100 A

class Q0{<br> static Object obj;<br> static String get(){<br> return null;<br> }<br> public static void main(String args[]){<br> System.out.println((Q0.get()) == (Q0.obj));<br> }<br> } A. Compile error B. Run-time error C. true D. false ANSWER: C int i =1,j =10;<br> do {<br> if(i++> --j) {<br> continue;<br> }<br> } while (i <5);<br> System.out.println("i A. i = 6 and j = B. i = 5 and j = C. i = 6 and j = D. i = 5 and j = ANSWER: D

= "+i+ "and j = "+j);<br> 5 5 5 6

interface Animal {<br> void soundOff();<br> }<br> class Elephant implements Animal {<br> public void soundOff() {<br> System.out.println("Trumpet");<br> }<br> }<br> class Lion implements Animal {<br> public void soundOff() {<br> System.out.println("Roar");<br> }<br> }<br> class Alpha1 {<br> static Animal get( String choice ) {<br> if ( choice.equalsIgnoreCase("meat eater")) {<br> return new Lion();<br> } else {<br> return new Elephant();<br> }<br> }<br> }<br> Which compiles : A. new Animal().soundOff(); B. new Alpha1().get("veggie").soundOff(); C. Lion 1 = Alpha.get("meat eater"); D. Elephant e = new Alpha1(); ANSWER: B public class SDF {<br> public static void aMethod() throws Exception {<br> try {<br> throw new Exception();<br> } finally {<br> System.out.print("finally");<br> }<br> }<br> public static void main(String args[]) {<br> try {<br> aMethod();<br> } catch (Exception e) {<br> System.out.print("exception");<br> }<br> System.out.print("finished");<br> }<br> } A. finally B. exceptionfinishedfinally C. finallyexceptionfinished D. Compilation fails. ANSWER: C Which of these are legal ways of accessing a File named "file.tst" for reading. A. FileInputReader fr = new FileInputReader("file.tst"); B. FileInputStream fr = new FileInputStream("file.tst"); C. FileReader fr = new FileReader("file.tst", "UTF8"); D. InputStreamReader isr = new InputStreamReader("file.tst"); Answer: B

TreeMap A. B. C. D. Answer:

class is used to implement which collection interface. Set SortedSet List SortedMap D

What will happen if you compile/run the following code? class Test {<br> static void show() {<br> System.out.println("Show method in Test class");<br> } <br> }<br> public class Q2 extends Test{<br> static void show() {<br> System.out.println("Show method in Q2 class");<br> }<br> public static void main(String []args){<br> Test t = new Test();<br> t.show();<br> Q2 q=new Q2();<br> q.show();<br> t=q;<br> t.show();<br> q=t; <br> q.show();<br> }<br> } A. prints "Show method in Test class" "Show method in Q2 class" "Show method in Q2 class" "Show method in Q2 class" B. prints "Show method in Test class" "Show method in Q2 class" "Show method in Test class" "Show method in Test class" C. prints "Show method in Test class" "Show method in Q2 class" "Show method in Test class" "Show method in Q2 class" D. Compilation error ANSWER: D public class RThread implements Runnable {<br> public void run (String s) {<br> System.out.println ("Executing Runnable" +s);<br> }<br> public static void main ( String args []) {<br> RThread rt = new RThread ( );<br> Thread tt = new Thread (rt);<br> tt.start( );<br> }<br> }<br> A. The compiler error B. The runtime error C. Compiles and prints "Executing Runnable Main" on the screen D. Compiles and does not print any thing on the screen ANSWER: A Which of the following is used by client to locate the reference<br> of remote object on the server machine in RMI<br> A. Naming.rebind(JNDIName , obj); B. Naming.find(JNDIName); C. InitialContext.lookup(JNDIName); D. Naming.lookup(JNDIName);

ANSWER: D At what point will the object created on line 8 be eligible for garbage<br> coll ection?<br> 1 public class RJMould{<br> 2 StringBuffer sb;<br> 3 public static void main(String argv[]){<br> 4 RJMould rjm = new RJMould();<br> 5 rjm.kansas();<br> 6 }<br> 7 public void kansas(){<br> 8 sb = new StringBuffer("Manchester");<br> 9 StringBuffer sb2 = sb;<br> 10 StringBuffer sb3 = new StringBuffer("Chester");<br> 11 sb=sb3;<br> 12 sb3=null;<br> 13 sb2=null;<br> 14 }<br> 15 }<br> A. Line 11 B. Line 9 C. Line 12 D. Line 13 ANSWER: D Consider the following main method in the TechnoSample class:<br> public static void main (String[] args){<br> String s1 = " Arg " + args[1] ;<br> s1.trim();<br> String s2 = ":" + s1 + args[2] ;<br> System.out.println( s2 + ":" );<br> }<br> What will be printed when this is executed with the<br> following command line?<br> java TechnoSample alpha beta gamma delta<br> A. :Arg alphagamma: B. :Argbetagamma: C. : Arg betagamma: D. : Arg alphabeta: ANSWER: C Which one is the correct url for type 4 driver? A. protocol_name:subprotocol_name:drivername:@host_name:port no:database_na me B. protocol_name:subprotocol_name:drivername:@database_name C. protocol_name:subprotocol_name:dsn_name D. protocol_name:subprotocol_name:drivername:@hostname ANSWER: A transient keyword can be used with? A. method B. variable C. class D. constructor ANSWER: B import public public Map ss java.util.*;<br> class Test5{<br> static void main(String a[]){<br> = new HashMap();<br>

ss.put("1","one");<br> ss.put("3","three");<br> ss.put("2","two");<br> System.out.println(ss);<br> }<br> }<br> What is the output? A. [1=one,3=three,2=two] B. [3=three,2=two,1=one] C. cannot predict the order D. [] ANSWER: C Which of the following is used to create client side proxy in RMI ? A. javac B. rmiregistry C. rmic D. RMISecurity public class Test14{<br> static String s ="Instance";<br> public static void method(String s){<br> s+="Add";<br> }<br> public static void main(String a[]){<br> Test14 tt = new Test14();<br> s = "New Instance";<br> String s = "Local";<br> method(s);<br> System.out.println(s);<br> System.out.println(tt.s);<br> }<br> }<br> What is output? A. Local Instance B. Local New Instance C. Loca Add New Instance D. Compiler Error ANSWER: B class CatchDemo{<br> public static void main(String [] args){<br> try{<br> int a=0;<br> int b=12/a;<br> }<br> catch(Exception e){<br> System.out.println("Exception.");<br> }<br> catch(ArithmeticException e){<br> System.out.println("Arithmatic exception.");<br> }<br> }<br> A. Exception. B. Arithmatic exception. C. compiletime error. D. runtime error. ANSWER: C What will be output if you try to compile and run the following code, but there

is<br> no file called Hello.txt in the current directory?.<br> import java.io.*;<br> public class Mine {<br> public static void main(String argv[]){<br> Mine m=new Mine();<br> System.out.println(m.amethod());<br> }<br> public int amethod() {<br> try {<br> FileInputStream dis=new FileInputStream("Hello.txt");<br> }catch (FileNotFoundException fne) {<br> System.out.println("No such file found");<br> return -1;<br> }catch(IOException ioe) {<br> } finally{<br> System.out.println("Doing finally");<br> }<br> return 0;<br> }<br> }<br> A. No such file found B. No such file found ,-1 C. No such file found, Doing finally, -1 D. 0 ANSWER: C You need to create a class that will store unique object elements.<br> You do not need to sort these elements but they must be unique.<br> What interface might be most suitable to meet this need?<br> A. Set B. List C. Map D. Vector ANSWER: A Given:<br> 1. int x= 10;<br> 2. do {<br> 3. x--;<br> 4. } while(x< 9);<br> How many times will line 3 be executed? A. only one time B. three time C. more than 10 time D. not executed once ANSWER: A class Pizza { java.util.ArrayList toppings; public void addTopping(String topping) { toppings.add(topping); } } public class PepperoniPizzas extends Pizza { public void addTopping(String topping) { System.out.println("Cannot add Toppings"); } public static void main(String[] args) { Pizza pizza = new PepperoniPizzas();

pizza.addTopping("Mushrooms"); } } What happen after execute the code ? A. Cannot add Toppings is printed B. compile time error C. code runs with no output D. NullPointerException is thrown ANSWER: A Given:<br> static void test() throws RuntimeException {<br> try {<br> System.out.print("test ");<br> throw new RuntimeException();<br> }<br> catch (Exception ex) {<br> System.out.print("exception "); }<br> } public static void main(String[] args) {<br> try { test(); }<br> catch (RuntimeException ex)<br> {<br> System.out.print("runtime ");<br> }<br> System.out.print("end ");<br> }<br> What is the result? A. test end B. runtime end. C. A Throwable is thrown by main at runtime D. test exception end ANSWER: D Given: String str = "Hello"; str.replace('H','T'); System.out.println(str); predict the output ? A. Tello B. Hello C. compliler error : incorrect way to define string D. compiler error : str is a reserve keyword ANSWER: B Assume that Sub1 and Sub2 are both subclasses of class Super.<br> Given the declarations:<br> Super super = new Super();<br> Sub1 sub1 = new Sub1();<br> Sub2 sub2 = new Sub2(); <br> Which statement best describes the result of attempting to compile and e xecute the following statement:<br> super = sub1;<br> A. Compiles and definitely legal at runtime B. Does not compile C. Compiles and may be illegal at runtime ANSWER: A

Consider this class example:<br> class MyPoint <br> { void myMethod()<br> { int x, y;<br> x = 5; y = 3;<br> System.out.print( " ( " + x + ", " + y + " switchCoords( x, y );<br> System.out.print( " ( " + x + ", " + y + " }<br> void switchCoords( int x, int y )<br> { int temp;<br> temp = x;<br> x = y;<br> y = temp;<br> System.out.print( " ( " + x + ", " + y + " }<br> } What is printed to standard output if myMethod() A. (5, 3) (5, 3) (5, 3) B. (5, 3) (3, 5) (3, 5) C. (5, 3) (3, 5) (5, 3) D. (3, 3) (3, 5) (5, 5) ANSWER: C

) " );<br> ) " );<br>

) " );<br> is executed?

Where in a constructor, can you place a call to a constructor defined in the sup er class A. Anywhere B. The first statement in the constructor C. The last statement in the constructor D. You can't call super in the constructor ANSWER: B Objects ? A. B. C. D. E. ANSWER: can be cast to another class when which one of the following is the case Both classes are The source class The target class Both classes are The target class C direct subclasses of the same superclass is not abstract or static is a subclass of the source class subclasses of the same abstract superclass is a final class

public class Q8 { int i = 20;<br> static {<br> int i = 10; <br> }<br> public static void main(String args[]) {<br> Q8 a = new Q8();<br> System.out.println(a.i);<br> }<br> A. B. C. D. ANSWER: } <br> Compilation error, variable "i" declared twice. Compilation error, static initializers for initialization purpose only Prints 10 Prints 20 D

What is the result of compiling and running the following:<br>

public class TestClass {<br> public static class Foo {<br> public void bar(int bar) {<br> System.out.println("Hello from Foo: " + bar);<br> }<br> }<br> public static class SubFoo extends Foo {<br> public void bar(int bar) {<br> System.out.println("Hello from SubFoo: " + bar);<br> }<br> }<br> public static void main(String[] args) {<br> Foo foo = new SubFoo();<br> foo.bar(123);<br> }<br> } A. The program doesn't compile B. The program prints "Hello from Foo 123" C. The program compiles, but throws an exception at runtime D. The program prints "Hello from SubFoo 123" ANSWER: B Consider the code below:<br> public static void main( String args[] ){ <br> int a = 5;<br> System.out.println( cube( a ) );<br> }<br> int cube( int theNum ) {<br> return theNum * theNum * theNum;<br> }<br> What will happen when you attempt to compile and run this code? A.It will not compile because cube is already defined in java.lang.Math class B.It will not compile because cube is not static C.It will compile but throw an arithmetic exception D.It will run perfectly and print "125" to standard output ANSWER: B

You might also like