all questions 1-50

Upload: hamid25

Post on 09-Apr-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 All Questions 1-50

    1/25

    All Questions

    #1 Given:

    1. public abstract class Prod {2. public abstract void prmth1();3. public static void prmth2() {4. int mth2 = 30;5. System.out.println("prmth2 = " + mth2);6. }7. public abstract void prmth3();8. }

    What is the result?

    (1) Compilation succeeds

    (2) Compilation fails because of an error on line 1

    (3) Compilation fails because of an error on line 3

    (4) Compilation fails because of an error on line 7

    Answer : -------------------------

    #2 Given:

    1. public class ClassA {2. public static void main(String [] args) {3.4. switch(x) {5. default:6. System.out.println("Here it is.");7. }8. }9. }

    The ClassA class can be compiled successfully by inserting one of three possibleoptions on line 3. When inserted separately, which three will allow compilationto succeed? (Choose three.)

    (1) int x = 6;

    (2) short x = 3;

    (3) char x = 'y';

    (4) long x = 354;

    (5) boolean x = true;

    Answer : -------------------------

  • 8/8/2019 All Questions 1-50

    2/25

  • 8/8/2019 All Questions 1-50

    3/25

    4. int p = 1;5. int t = 0;6. for(;p < 5;p++) {7. if(t++ > m) {8. m = p + t;9. }

    10. }

    11. System.out.println("t equals " + t);12. }13. }

    What is the resulting value of t?

    (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) public Char getType(String a, int b, char c) {

    (2) public Char getType(int b, String a, char c) {

    (3) public String getType(String a, int b, char c) {

  • 8/8/2019 All Questions 1-50

    4/25

    (4) public String getType(int b, String a, char c) {

    Answer : -------------------------

    #7 Given:

    1. public class MyThread implements Runnable {2. private String holdA = "This is ";3. private int[] holdB = {1,2,3,4,5,6,7,8,9,10};4.5. public static void main(String args[]) {6. MyThread z = new MyThread();7. (new Thread(z)).start();8. (new Thread(z)).start();9. }

    10.

    11. public synchronized void run() {12. for(int w = 0;w < 10;w++) {13. System.out.println(holdA + holdB[w] + ".");14. }15. }16. }

    What is the result?

    (1) Compilation fails because of an error on line 6

    (2) Compilation fails because of an error on line 11

    (3) Compilation fails because of errors on lines 7 and 8

    (4) Compilation succeeds and the program prints each value in the holdB array at the end of the "This is " line. Each value is printed two times before the program ends, and the valuesare not printed in sequential order

    (5) Compilation succeeds & the prog. prints each val in the holdB array at the end of the "Thisis " line. Each val is printed in order from 1-10 & after the val 10 prints, it starts printingthe vals 1-10 in order again

    Answer : -------------------------

    #8 Given:

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

  • 8/8/2019 All Questions 1-50

    5/25

    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 compileand run with all defined fields properly displayed?

    (1) public static void main(String args[]) { Frame.visible = true; }

    (2) public static void main(String args[]) { Frame f = new Frame(); f.setVisible(true);}

    (3) public static void main(String args[]) { Birthdays b = new Birthdays(); b.pack();b.setVisible(true); }

    (4) public static void main(String args[]) { Frame f = Birthdays.new Frame(); f.pack(); f.visible= true; }

    Answer : -------------------------

    #9 Given:

    1. public class GetIt {2. public static void main(String args[]) {3. double x[] = {10.2, 9.1, 8.7};4. int i[] = new int[3];5. for(int a = 0;a < (x.length);a++) {6.7. System.out.println(i[a]);8. }9. }

    10. }

    The GetIt class should print the following:1110

    9

    Which line should you insert on line 6 to accomplish this?

    (1) i[a] = ((int)Math.min(x[a]));

    (2) i[a] = ((int)Math.max(x[a]));

    (3) i[a] = ((int)Math.ceil(x[a]));

    (4) i[a] = ((int)Math.floor(x[a]));

    Answer : -------------------------

    #10 Which statement about the Map interface is true?

  • 8/8/2019 All Questions 1-50

    6/25

    (1) Entries are placed in a Map using the values() method

    (2) Entries are placed in a Map using the entrySet() method

    (3) A key/value association is added to a Map using the put() method

    (4) A key/value association is added to a Map using the putAll() method

    Answer : -------------------------

    #11 Consider this class:

    1. public class Test1 {2. public float aMethod(float a, float b) {3. }4.5. }

    Which of the following methods would be legal if added (individually) at line 4?

    (1) public int aMethod(int a, int b) { }

    (2) public float aMethod(float a, float b) { }

    (3) public float aMethod(float a, float b, int c) throws _Exception { }

    (4) public float aMethod(float c, float d) { }

    (5) private float aMethod(int a, int b, int c) { }

    Answer : -------------------------

    #12 Consider these classes, defined in separate source files:

    1. public class Test1 {2. public float aMethod(float a, float b)

    throws IOException {3. }4. }

    1. public class Test2 extends Test1 {2.3. }

    Which of the following methods would be legal (individually) at line 2 in class Test2?

    (1) float aMethod(float a, float b) { }

    (2) public int aMethod(int a, int b) throws Exception { }

    (3) public float aMethod(float a, float b) throws _Exception { }

    (4) public float aMethod(float p, float q) { }

    Answer : -------------------------

    #13 You have been given a design document for a veterinary registration system for

  • 8/8/2019 All Questions 1-50

    7/25

    implementation in Java technology. It states:

    "A pet has an owner, a registrat ion date, and a vaccination-due date. A cat is a pet that has a f lag indicat ing if i t has been neutered, and a

    textual descript ion of i ts markings."

    Given that the Pet class has already been defined, which of the following fields would beappropriate for inclusion in the Cat class as members?

    (1) Pet thePet;

    (2) Date registered;

    (3) Date vaccinationDue;

    (4) Cat theCat;

    (5) boolean neutered;

    (6) String markings;

    Answer : -------------------------

    #14 You have been given a design document for a veterinary registration system forimplementation in Java. It states: "A pet has an owner, a registration date, and avaccination-due date. A cat is a pet that has a flag indicating if it has been neutered, and atextual description of its markings." Given that the Pet class has already been defined andyou expect the Cat class to be used freely throughout the application, how would you makethe opening declaration of the Cat class, up to but not including the first opening brace?Use only these words and spaces: boolean, Cat, class, Date, extends, Object, Owner, Pet,private, protected, public, String.

    Answer : -------------------------

    #15 Consider the following classes, declared in separate source files:

    1. public class Base {2. public void method(int i) {3. System.out.println("Value is " + i);

    4. }5. }

    1. public class Sub extends Base {2. public void method(int j) {3. System.out.println("This value is " + j);4. }5. public void method(String s) {6. System.out.println("I was passed " + s);7. }8. public static void main(String args[]) {9. Base b1 = new Base();

    10. Base b2 = new Sub();11. b1.method(5);12. b2.method(6);13. }14. }

  • 8/8/2019 All Questions 1-50

    8/25

    What output results when the main method of the class Sub is run?

    (1) Value is 5Value is 6

    (2) This value is 5

    This value is 6(3) Value is 5

    This value is 6

    (4) This value is 5Value is 6

    (5) I was passed 5I was passed 6

    Answer : -------------------------

    #16 Consider the following class definition:

    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. }

    Which of the following are legitimate calls to construct instances of the Test class?

    (1) Test t = new Test();

    (2) Test t = new Test(1);

    (3) Test t = new Test(1, 2);

    (4) Test t = new Test(1, 2, 3);

    (5) Test t = (new Base()).new Test(1);

    Answer : -------------------------

    #17 Consider the following class definition:

    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. }

    Which of the following forms of constructor must exist explicitly in the definition of the Baseclass?

  • 8/8/2019 All Questions 1-50

    9/25

    (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) 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 : -------------------------

    #19 Consider the following definition:

    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. }

    Which variables may be referenced correctly at line 8?

    (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 appropriateconstructor forms are defined, an instance of Inner may be constructed like this:

    n e w Ou te r ( ) . new Inne r ( )

  • 8/8/2019 All Questions 1-50

    10/25

    (2) If an anonymous inner class inside the class Outer is defined to implement the interfaceActionListener, 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 appropriateconstructor forms are defined, an instance of Inner may be constructed in a static methodlike this:

    new Inner()

    (4) An anonymous class instance that implements the interface MyInterface may beconstructed and returned from a method like this: 1. return new MyInterface(int x) { 2. intx; 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(); // 2synchronized (this) {

    while (J.notFinalized() > 0) {try {wait();} catch (InterruptedException ie) {}

    }}

    }public static void main(String[] args) {

    new K().m1();}

    }

    When the processing of line 2 begins how many objects of type J that were created at line1 are eligible for garbage collection?

    (1) 0

    (2) 1

  • 8/8/2019 All Questions 1-50

    11/25

    (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 correctanswers

    1 public class Sample {2 public static void main(String[] args){

    3 int y=0;4 int x=z=1;5 System.out.println(y+","+x+","+z);6 }7 }

    (1) Prints 0,1,1

    (2) Error during compilation at line 3

    (3) Prints 0,0,1

    (4) Error during compilation at line 4(5) Error during compilation at line 5

    Answer : -------------------------

    #23 What is the output of the following code when compiled and run? Select one correct answer

    1 public class Sample {2 public static void main(String[] args){3 int j = 017;4 int i = (byte)j >> 2;5 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

  • 8/8/2019 All Questions 1-50

    12/25

    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 correctanswer.

    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 TechnoSampleIn TechnoSampleSub

    (4) Prints:

    In TechnoSampleSubIn TechnoSample

    (5) The code does not compile

    Answer : -------------------------

  • 8/8/2019 All Questions 1-50

    13/25

    #26 What is the output of the following code when compiled and run with the followingcommand line: java TechnoSample two three? Select two correct answers.

    public class TechnoSample {public static void main(String[] args) throws Exception {

    int i=2;

    boolean b = true;throw new Exception("Values are:"+(b!=b)+","+(i=args.length)+","+(b=i==2));}

    }

    (1) The exception message is Values are:false,3,true

    (2) The exception message is Values are:true,2,false

    (3) The exception message is Values are:false,2,true

    (4) The final value of b is false

    (5) An exception is thrown at runtime

    Answer : -------------------------

    #27 Select two correct statements about the code given below?

    class A{}class B extends A implements E{} //line 1class C extends A{}class D extends B{}interface E{}public class Question07 {

    public static void main(String[] args) {A a = new D(); //line 2C c = new C(); //line 3E e = (E)a; //line 4B b = (B)e; //line 5

    }}

    (1) The code compiles without error and runs fine

    (2) Compilation error on line 1 because interface E is not yet declared (forward-referencing)

    (3) Compilation error on line 4 because class A does not implement interface E

    (4) The cast on line 4 is mandatory

    (5) The cast on line 5 is not mandatory

    Answer : -------------------------

    #28 How many objects are eligible for garbage collection immediately after line 1? Select onecorrect answer.

    public class TechnoGC {

  • 8/8/2019 All Questions 1-50

    14/25

  • 8/8/2019 All Questions 1-50

    15/25

    answer.

    public class TechnoSample {

    public static void main(String[] args) {new TechnoSample().doSomething();

    }

    public void doSomething(){int i=5;Thread t = new Thread(new Runnable(){

    public void run(){for(int j=0;j

  • 8/8/2019 All Questions 1-50

    16/25

    Hel lo o r l d

    He l lo o r l d

    (3) Prints

    He l l o o r l d

    e l l o o r l d

    (4) Prints

    e l l o o r l d

    e l l o o r l d

    (5) Compilation error

    Answer : -------------------------

    #32 What is the output of the following code when compiled and run? Select two correctanswers. (Note: when an instance of a Vector is printed, its content appear between squarebrackets [])

    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 1col.add(col.elementAt(1));col.setElementAt(col.elementAt(2),0);System.out.println(col);

    }}

    (1) Compilation error on line 1

    (2) Only line 1 won't compile

    (3) The code compiles and runs fine

    (4) Prints [3.2, 2, 3.2, 2]

    (5) Prints [1, 2, 3.2, 2]

    Answer : -------------------------

    #33 What is the output of the following code when compiled and run? ('\u0048' is 'H' and'\u000a' is a linefeed (LF)). Select two correct answers.

    public class TechnoSample {public static void main(String[] args) {

    String s = "\u0048ello\u000aWorld!";System.out.println(s);

    }}

  • 8/8/2019 All Questions 1-50

    17/25

    (1) Prints:

    He l l o

    Wor ld !

    (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 correctanswers.

    public class TechnoSample {public static void main(String[] args) {

    int i = 2;try {

    if((i/=(int)Math.floor(Math.random())) > 1)System.out.println("No arithmetic exception");

    } catch (ArithmeticException ae){System.err.println("Arithmetic exception caught");

    }}

    }

    (1) Compilation error

    (2) No arithmetic exception will never be printed

    (3) The final value of i is 2

    (4) The final value of i is 0

    (5) The try-catch block is necessary for the code to compile

    Answer : -------------------------

    #35 What is the output of the following code when compiled and run? Select two correctanswers.

    public class TechnoSample {public static void main(String[] args) throws Exception{

    Thread t1 = new Thread(getRunnable(3));Thread t2 = new Thread(getRunnable(4));t1.join();System.out.println("End");

    }

    public static Runnable getRunnable(final int id){return new Runnable(){

    public void run(){for(int i = 0; i < id; i++){

  • 8/8/2019 All Questions 1-50

    18/25

    System.out.print(" "+i);}

    }};

    }}

    (1) The output will always be the same whatever the underlying platform is

    (2) Prints: End

    (3) Prints:

    0 1 2

    En d

    (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 correctanswers.

    public class TechnoSample {

    public static void main(String[] args){for(int i = 0; i < 10; i++){

    System.out.println(getPrimitive(127)); //line 1}

    }public static int getPrimitive(byte b){ //line 2

    return (short)(Math.random()*b); //line 3}

    }

    (1) Compilation error on line 1

    (2) Compilation error on line 2

    (3) Compilation error on line 3

    (4) Line 3 compiles fine

    (5) Prints 10 random numbers between 0 and 127

    Answer : -------------------------

    #37 Select three correct statements.

    (1) A static method may override another static method(2) A static method cannot override a non-static method

    (3) A non-static method cannot override a static method

    (4) A non-static method may be overloaded by a static method

  • 8/8/2019 All Questions 1-50

    19/25

    (5) A synchronized method cannot be overridden

    Answer : -------------------------

    #38 Select three correct statements about the following code.

    public class TechnoSample {

    public static void main(String[] args) {TechnoSample myref = new TechnoSampleSub();try{

    myref.test();}catch(Exception e){}

    }void test() throws Exception{

    System.out.println("In TechnoSample");throw new Exception();

    }}class TechnoSample Sub extends TechnoSample {

    void test() {System.out.println("In TechnoSampleSub");

    }}

    (1) The try-catch block that encloses myref.test(); is mandatory for the code to compile

    (2) Prints: In TechnoSample

    (3) Prints: In TechnoSampleSub

    (4) Method test() in class TechnoSampleSub has no obligation to declare a throws clause

    (5) An exception is thrown at runtime

    Answer : -------------------------

    #39 Given the following code:

    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);}

    public static void method(Date d1, Date d2) {d2.setYear (100);d1 = d2;

    }}

  • 8/8/2019 All Questions 1-50

    20/25

    Which one or more of the following correctly describe the behavior when this program iscompiled and run?

    (1) compilation is successful and the output is:

    d1 is Fri December 31 00:00:00 GMT 1999 d2 is Fri December 31 00:00:00 GMT 1999

    (2) compilation is successful and the output is:

    d1 is Fri December 31 00:00:00 GMT 1999 d2 is Sun December 31 00:00:00 GMT 2000

    (3) compilation is successful and the output is:

    d1 is Sun December 31 00:00:00 GMT 2000 d2 is Sun December 31 00:00:00 GMT 2000

    (4) the assignment 'd1 = d2' is rejected by the compiler because the Date class cannotoverload the operator '='

    (5) the expression (d1 is " + d1 + "\nd2 is " + d2) is rejected by the compiler because theDate class cannot overload the operator '+'

    Answer : -------------------------

    #40 Read this piece of code carefully

    i f("Str ing". toString() == "String")

    System.out .print ln("Equal");

    else

    System.out .print ln("Not Equal");

    (1) the code will compile an print "Equal"

    (2) the code will compile an print "Not Equal"

    (3) the code will cause a compiler error

    Answer : -------------------------

    #41 Given the following code

    class Base{static int oak=99;

    }

    public class Doverdale extends Base {public static void main(String argv[]) {

    Doverdale d = new Doverdale();d.amethod();

    }

    public void amethod() {//Here

    }}

  • 8/8/2019 All Questions 1-50

    21/25

    Which of the following if placed after the comment //Here, will compile and modify thevalue of the variable oak?

    (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?

    public class TechnoSample {public static void main(String argv[]) {

    TechnoSample inc = new TechnoSample();int i =0;inc.fermin(i);i = i++;System.out.println(i);

    }

    void fermin(int i) {i++;

    }}

    (1) Compile time error

    (2) Output of 2

    (3) Output of 1

    (4) Output of 0

    Answer : -------------------------

    #43 Given the following class

    public class ZeroPrint {public static void main(String argv[]) {

    int i =0;//Here

    }}

    Which of the following lines if placed after the comment //Here will print out 0.

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

  • 8/8/2019 All Questions 1-50

    22/25

    (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?

    private class Base {}

    public class Vis {transient int iVal;

    public static void main(String elephant[]) {}

    }

    (1) Compile time error: Base cannot be private

    (2) Compile time error indicating that an integer cannot be transient

    (3) Compile time error transient not a data type

    (4) Compile time error malformed main method

    Answer : -------------------------

    #45 What best describes the appearance of an application with the following code?

    import java.awt.*;

    public class FlowAp extends Frame {public static void main(String argv[]) {

    FlowAp fa=new FlowAp();fa.setSize(400,300);fa.setVisible(true);

    }

    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

  • 8/8/2019 All Questions 1-50

    23/25

  • 8/8/2019 All Questions 1-50

    24/25

    class Value{

    public int i = 15;} //Value

    public class Test{

    public static void main(String argv[]){Test t = new Test();t.first();

    }

    public void first(){

    int i = 5;Value v = new Value();v.i = 25;second(v, i);System.out.println(v.i);

    }

    public void second(Value v, int i){

    i = 0;v.i = 20;Value val = new Value();v = val;System.out.println(v.i + " " + i);

    }

    } // Test

    (1) 1 5 02 0

    (2) 1 5 01 5

    (3) 2 0 02 0

    (4) 0 152 0

    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 asit is, which keywords can legally be placed before myMethod on line 8?

    1. class HumptyDumpty2. {3. void myMethod() {}

    4. }5.6. class HankyPanky extends HumptyDumpty7. {8. void myMethod() {}9. }

  • 8/8/2019 All Questions 1-50

    25/25

    (1) private or nothing (i.e. leaving it as it is) on line 3. Nothing (i.e. leaving it as it is) orprotected or public on line 8

    (2) public or protected on line 3. private or nothing (i.e. leaving it as it is) on line 8

    (3) nothing (i.e. leaving it as it is) or protected or public on line 3. private or nothing (i.e.leaving it as it is) on line 8

    (4) None of the above

    Answer : -------------------------

    #50 What is the result when you compile 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);}

    }} // ThrowsDemo

    (1) Compilation error

    (2) Runtime error(3) Compile successfully, nothing is printed

    (4) Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo

    Answer : -------------------------

    2001-2003 Technopark . Developed by: Giri Mandalika