Results 1 to 5 of 5
  1. #1
    idrees is offline Member
    Join Date
    Nov 2007
    Posts
    1
    Rep Power
    0

    Default Some question to be solved

    Can some one help me in solving this exam. I am an SAP consultant and someone at my work give me to check this paper. I need a solved copy to mark applicants gone thorgh this test in my organization. The person who wrote this test has left the company and not anymore with us and I have not used java from last 10 years. Your help will be highly appreciated.


    Question 1. What happens when you attempt to compile and execute the following code?

    1. class A {
    2. public static void main(String[] args) {
    3. Integer i = new Integer(5);
    4. i.setIntValue(i.intValue()+1);
    5. System.out.println("i = " + i);
    6. }
    7. }


    A) Compiler error.
    B) The code prints out "i = 5".
    C) The code prints out "i = 6".
    D) The code prints out "i = 7".

    Question 2. What is the result of attempting to compile and execute the following application?
    1. public class X {
    2. int[] intarr;
    3.
    4. public static void main(String[] args) { new X(); }
    5.
    6. X() {
    7. int s = 100;
    8. intarr = new int[s];
    9. System.out.println("value = " + intarr[s-1]);
    10. System.out.println("value = " + intarr[s]);
    11. }
    12. }


    A) Compiler error on line 8.
    B) Compiler error on line 9.
    C) Compiler error on line 10.
    D) The code compiles, but throws an exception at line 9.
    E) The code compiles, but throws an exception at line 10.
    F) The code compiles and executes with no exceptions.


    Question 3. In the following code, does line 7 compile?
    1. class Outside {
    2. private float i;
    3.
    4. void amethod(float j) {
    5. class Inside {
    6. void innerFoo() {
    7. float k = i + j;
    8. System.out.println("k = " + k);
    9. }
    10. }
    11. }
    12. }


    A) Yes
    B) No


    Question 4. What happens when you try to compile and run the following application?
    1. import java.io.*;
    2. class C {
    3. public static void main(String[] args) {
    4. try {
    5. RandomAccessFile raf =
    6. new RandomAccessFile("f", "rw");
    7. DataOutputStream dos = new DataOutputStream(raf);
    8. dos.writeFloat(-5.6f);
    9. dos.close();
    10. DataInputStream dis = new DataInputStream(raf);
    11. float f = dis.readFloat();
    12. dis.close();
    13. raf.close();
    14. System.out.println(f);
    15. }
    16. catch (IOException e) { System.out.println("Oops"); }
    17. }
    18. }

    A) Compiler error.
    B) The program prints out "-5.6".
    C) The program prints out a numeric value other than -5.6.
    D) The program prints out "Oops".

    Question 5. In the following code, what are the legal types for the variable vari , which is declared and constructed on line 11? Just think about the type of vari; assume the declaration and construction on line 11 are legal. Choose all correct options.

    1. class Fruit {}
    2. class Apple extends Fruit { }
    3. interface Squeeze {}
    4. class Citrus extends Fruit implements Squeeze {}
    5. class Orange extends Citrus {}
    6.
    7. class NavelOrange extends Orange {
    8. static void foo(Citrus c) { }
    9.
    10. public static void main(String[] args) {
    11. ??? vari = ???;
    12. foo(vari);
    13. }
    14. }

    A) Fruit
    B) Apple
    C) Squeeze
    D) Citrus
    E) Orange
    F) NavelOrange



    Question 6. What happens when you attempt to compile the following code?

    1. class A { static void foo() {}; }
    2. class B extends A { public static void foo() {}; }

    A) Compiler error at line 1.
    B) Compiler error at line 2.
    C) No compiler error.

    Question 7. Given the following code, which access modifiers can legally be placed before aMethod() on line 6? Choose all correct options.
    1. class Thing {
    2. void aMethod() { }
    3. }
    4.
    5. class SubThing extends Thing {
    6. void aMethod() { }
    7. }

    A) public
    B) protected
    C) private


    Question 8. Does this code compile?
    1. class SubEx extends Exception { }
    2.
    3. class Parent {
    4. protected void foo(int i) throws Exception {
    5. if (i > 20)
    6. throw new Exception();
    7. }
    8. }
    9.
    10. class Kid extends Parent {
    11. void foo(int i) throws SubEx {
    12. if (i < 20)
    13. throw new SubEx();
    14. }
    15. }

    A) Yes
    B) No

    Question 9. Consider the following class definition:
    1. public class Sub extends Supe {
    2. int i,j, k;
    3. Sub(int x) { i=1; j=2; k=3; }
    4. Sub(int x, int y) { super(x); k=3; }
    5. }
    Which of the following forms of constructor must exist in the Supe class? Choose all correct options.

    A) Supe()
    B) Supe(int i)
    C) Supe(int i, int j)
    D) Supe(int i, int j, int k)


    Question 10. What happens when you try to compile and execute the following application with the command-line argument "1"? Choose all correct options.
    1. class Switcheroo {
    2. public static void main(String[] args) {
    3. int i = 0;
    4. try {
    5. i = Integer.parseInt(args[0]);
    6. }
    7. catch (Exception e) { }
    8.
    9. switch (i) {
    10. case 0:
    11. System.out.println("zero");
    12. case 1:
    13. System.out.println("one");
    14. default:
    15. System.out.println("default");
    16. }
    17. }
    18. }


    A) Compiler error.
    B) The program prints "zero".
    C) The program prints "one".
    D) The program prints "default".

    11. What happens when you run the following application?
    1. class Q extends Thread {
    2. public void run() {
    3. for (int i = 0; i < 1000; i++)
    4. System.out.println(i);
    5. }
    6.
    7. public static void main(String[] args) {
    8. Q that = new Q();
    9. that.run();
    10. for (int j = 999; j >= 0; j--)
    11. System.out.println(j);
    12. }
    13. }

    A) The code concurrently counts up to 999 and down from 999.
    B) The code first counts up to 999, and then counts down from 999.
    C) The code first counts down from 999, and then counts up to 999.


    Question 12. Consider the following code:
    1. interface Inter { }
    2. class A { }
    3. class B extends A implements Inter { }
    4. class C extends B {
    5. public static void main(String[] args) {
    6. A a = new A();
    7. B b = new B();
    8. C c = new C();
    9. if (a instanceof B)
    10. System.out.println("Hello");
    11. if (b instanceof A)
    12. System.out.println("Hello");
    13. if (c instanceof C)
    14. System.out.println("Hello");
    15. if (c instanceof Inter)
    16. System.out.println("Hello");
    17. }
    18. }

    When you run class C as an application, which of the following lines execute?


    A) Line 10
    B) Line 12
    C) Line 14
    D) Line 16

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Wow... where's the forum moderation when you need it... ? These types of posts should be illegal or moved elsewhere.

    OP, nice story, but I don't buy it. Judging by the fact you haven't received an answer in over a month, please do not post your homework. If you really need to get your work done, finding a freelancing site isn't such a bad idea.

  3. #3
    simi's Avatar
    simi is offline Member
    Join Date
    Dec 2007
    Location
    Singapore
    Posts
    18
    Rep Power
    0

    Default

    1.A
    2.E
    3.B
    4.A
    5.A,D
    6.C
    7.c
    8.b
    9.a,b
    10.c & D
    11.b
    12.b,c & d

    All the best.

  4. #4
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    idrees, that is THE most b.s. story I've ever seen. if you're gonna ask people to do your homework, at least have the decency to tell the truth. And by the way, if you're enrolled in a programming class, it's not gonna help if you receive other people's answers, come final exam time.

  5. #5
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    I think that question was from javablackbelt.com,

    My comment "fake belt does more harm than it does good".
    dont worry newbie, we got you covered.

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. [SOLVED] something important i want to know
    By pheonix in forum New To Java
    Replies: 5
    Last Post: 04-11-2008, 07:44 PM
  3. [SOLVED] Need help with Loops...please!
    By Zebra in forum New To Java
    Replies: 5
    Last Post: 04-10-2008, 02:44 PM
  4. [SOLVED] file i/o problem
    By aytidaalkuhs in forum New To Java
    Replies: 3
    Last Post: 04-06-2008, 07:42 PM
  5. [SOLVED] Error
    By Azndaddy in forum New To Java
    Replies: 3
    Last Post: 04-04-2008, 04:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •