Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-17-2007, 09:16 PM
Member
 
Join Date: Nov 2007
Posts: 1
idrees is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-25-2007, 11:15 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-02-2008, 11:06 AM
simi's Avatar
Member
 
Join Date: Dec 2007
Location: Singapore
Posts: 18
simi is on a distinguished road
Send a message via Yahoo to simi
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-02-2008, 11:59 PM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-03-2008, 12:13 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 286
roots is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question mark colon operator question orchid Advanced Java 8 11-27-2008 08:36 AM
[SOLVED] something important i want to know pheonix New To Java 5 04-11-2008 08:44 PM
[SOLVED] Need help with Loops...please! Zebra New To Java 5 04-10-2008 03:44 PM
[SOLVED] file i/o problem aytidaalkuhs New To Java 3 04-06-2008 08:42 PM
[SOLVED] Error Azndaddy New To Java 3 04-04-2008 05:10 AM


All times are GMT +3. The time now is 10:06 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org