Forums Register Login

Mock Exams Help

+Pie Number of slices to send: Send
Could anyone help me with these mock exams for my java course. I have answered some of the questions and just want to know if thy are correct. We did not get the answers to these mock exams.

http://rapidshare.de/files/10577838/Mock_Exams.zip.html


Thanks.
+Pie Number of slices to send: Send
If any one could help with the answers i would apperiacte. I would also like it to be completed by the end of the week thanks.
+Pie Number of slices to send: Send
Hmm, cant seem to download the file from the site. It says it cant find it. Have you got another way to send it?
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
If there are any questions you need help with, please feel free to post them here. I am disinclined to download an untrusted file that could possible have viruses and spyware with it. But I will be more than happy to answer your questions if you copy and paste specific ones here.

Layne

[ January 09, 2006: Message edited by: Layne Lund ]
[ January 09, 2006: Message edited by: Layne Lund ]
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
has any one got any answers for these
+Pie Number of slices to send: Send
Do you have specific questions that you need help with? Please check out our FAQ for some suggestions on how to ask your questions in such a way that you will recieve the answers you want.

Layne
+Pie Number of slices to send: Send
The Questions i am having mos diofficulty on are:
exam 1:

7. Consider the following code:
class Test
{
public interface Inner
{
public int getValue();
}
public Inner makeInner(int i)
{
return new Inner()
{
public int getValue()
{
return i;
} };
} }
This will raise a compile-time error; why?
A. Interfaces cannot be declared within a class. 􀀀
B. There should not be a semicolon after getValue(). 􀀀
C. There should not be a semicolon on the second-last line. 􀀀
D. The variable i should be declared final. 􀀀
E. The variable i should be declared static.

8. Consider the following code:
interface Number
{
public int getValue();
}
class Test
{
class Zero implements Number
{
public int getValue()
{
return 0;
} }
public static final Number zero = new Zero();
}
This will raise a compile-time error; why?
A. Number is not public and therefore not in scope within Test. 􀀀
B. There is no body for the method getValue() in the interface Number. 􀀀
C. There should be a semicolon at the end of the declaration of Zero. 􀀀
D. The eld zero is declared static, so the class Zero should be declared static. 􀀀
E. The field zero is declared final, so the class Zero should be declared final.

15. Consider the following fragment of code:
synchronized(new Integer(0))
{
for (int i=0; i<5; i++)
{
System.out.println();
} }
Which of the following best describes the correctness of the code?
A. The code will cause a compile-time error because new Integer(0) is not static. 􀀀
B. The code will cause a compile-time error because System.out is not static. 􀀀
C. The code will compile, but it will probably not behave as expected, because it will prevent all other
classes from referring to System.out at run-time. 􀀀
D. The code will compile, but it will probably not behave as expected, because new Integer(0)
will create a new key-keeper each time the code is executed. 􀀀
E. The code will compile, but it will almost certainly cause deadlock.


30. Consider the following fragment of code:
JFrame f = new JFrame("Test Frame");
f.add(new JButton("Quit"), BorderLayout.CENTER);
f.pack();
f.setVisible(true);
What is wrong with this code?
A. The JFrame constructor does not take a String parameter. 􀀀
B. The default layout of a JFrame is not BorderLayout. 􀀀
C. The getContentPane() method should be used to add the button. 􀀀
D. JFrame does not have a pack() method. 􀀀
E. The show() method should be used instead of setVisible().


35. Consider the following Java command:
BufferedReader br =
new BufferedReader(
new InputStreamReader(System.in)
);
Which of the following statements is false?
A. The command allows lines of text to be read from standard input. 􀀀
B. The command allows keyboard input to be read efciently by storing characters in a buffer. 􀀀
C. The command allows keyboard input to be written to a le. 􀀀
D. The command converts the byte-oriented standard input stream to a character stream. 􀀀
E. The command is an example of the use of wrapper classes.


36. Which of the following fragments of code will allow strings to be added to a le called `testoutput'?
A. File f = new File("testoutput");
f.println();
􀀀
B. File f = new File("testoutput");
FileInputStream fis = new FileInputStream(f);
􀀀
C. File f = new File("testoutput");
FileWriter fw = new FileWriter(f);
􀀀
D. File f = new File("testoutput");
OutputStream os = f.getOutPutStream();
􀀀
E. File f = new File("testoutput");
InputStream is = f.getInputStream();
FileOutputStream fos = new FileOutputStream(is);


37. Consider the following fragment of Java code:
try {
FileInputStream fis = ...;
FileOutputsStream fos = ...;
...
}
catch (IOException ioe){}
finally {
fis.close();
fos.close();
}
Which of the following statements describes the effect of the finally-block?
A. The code will close the le I/O streams, whether or not an exception is thrown. 􀀀
B. The code will close the le I/O streams only if an exception is thrown. 􀀀
C. The code will close the le I/O streams only if an exception is thrown that is not of type
IOException. 􀀀
D. The code will close the le I/O streams only if no exceptions are thrown. 􀀀
E. The code will not compile because finally is not a keyword in Java.
+Pie Number of slices to send: Send
Exam2:

Questions 1 and 2 refer to the following Java declarations.
class APrinter
{
APrinter() { System.out.print("A"); }
APrinter(int i) { System.out.print("A"+i); }
}
class BPrinter extends APrinter
{
BPrinter() { System.out.print("B"); }
BPrinter(int i)
{
super(i);
System.out.print("B");
}
}
class CPrinter extends BPrinter
{
CPrinter(int i) { System.out.print("C"+i); }
}
1. Consider the Java declarations above. What would you expect to see on standard output when an
instance of BPrinter is created with new BPrinter(1)?
A. AA1B 􀀀
B. A1B 􀀀
C. AB1B 􀀀
D. B1B 􀀀
E. BB 􀀀

2. Look again at the Java code above. What would you expect to see on standard output when an instance
of CPrinter is created with new CPrinter(2)?
A. C2 􀀀
B. BC2 􀀀
C. B2C2 􀀀
D. ABC2 􀀀
E. A2BC2 ?


3. Suppose the following two classes are declared in separate les in the same directory:
class Point
{
int xCoord, yCoord;
Point(int x, int y) { xCoord = x; yCoord = y; }
private void scale(int factor)
{
xCoord *= factor; yCoord *= factor;
} }
class ThreeDPoint extends Point
{
int zCoord;
ThreeDPoint(int x, int y, int z)
{
xCoord = x; yCoord = y; zCoord = z;
}
private void scale(int factor)
{
super.scale(factor); zCoord *= factor;
} }
Possible causes for compile-time errors might be:
1. the class Point is not public, and therefore cannot be subclassed by ThreeDPoint;
2. the elds xCoord and yCoord are not protected, and therefore not in scope in class
ThreeDPoint;
3. class Point does not have a constructor with no arguments;
4. method scale(int) is private, and not in scope in class ThreeDPoint;
5. the keyword super can only be used to refer to constructors.
Which of these are real causes of compile-time errors?
A. 1 and 5 only. 􀀀
B. 2 and 4 only. 􀀀
C. 3 and 4 only. 􀀀
D. 2, 3 and 4 only. 􀀀
E. 2, 4 and 5 only

9. Consider the following code:
class Test
{
public interface Inner
{
public int getValue();
}
public Inner makeInner(int i)
{
return new Inner()
{
public int getValue()
{
return i;
} };
} }
This will raise a compile-time error; why?
A. Interfaces cannot be declared within a class. 􀀀
B. The variable i should be declared final. 􀀀
C. The variable i should be declared static. 􀀀
D. There should not be a semicolon after getValue(). 􀀀
E. There should not be a semicolon on the second-last line.


12. Consider the following declarations.
static void printArray(int[] a, int i)
{
System.out.println(a[i]); // print the ith element
printArray(a,i+1); // repeat for i+1
}
public static void main(String[] args)
{
int[] is = new int[]{1,2,3,4};
printArray(is,0);
}
When the main() method is run, an exception is thrown; how many method calls are in the stack
trace?
A. One. 􀀀
B. Two. 􀀀
C. Four. 􀀀
D. Six. 􀀀
E. Eight.


31. Consider the following fragment of code where strings s1 and s2 have been declared and assigned
values:
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
jp.add(new JButton(s1), BorderLayout.NORTH);
jp.add(new JTextArea(12,12), BorderLayout.CENTER);
jp.add(new JButton(s2), BorderLayout.SOUTH);
When the panel jp is displayed on the screen, which of the following determines the width of the
button at the top of the panel?
A. The width of the string s1. 􀀀
B. The width of the JTextArea. 􀀀
C. The maximum of the widths of s1 and the JTextArea. 􀀀
D. The maximum of the widths of s2 and the JTextArea. 􀀀
E. The maximum of the widths of s1, s2 and the JTextArea.


32. Consider the following fragment of code:
JFrame f = new JFrame("Test Frame");
f.add(new JButton("Quit"), BorderLayout.CENTER);
f.pack();
f.setVisible(true);
What is wrong with this code?
A. The JFrame constructor does not take a String parameter. 􀀀
B. The default layout of a JFrame is not BorderLayout. 􀀀
C. The getContentPane() method should be used to add the button. 􀀀
D. JFrame does not have a pack() method. 􀀀
E. The show() method should be used instead of setVisible().
[ January 12, 2006: Message edited by: Jim Owen ]
+Pie Number of slices to send: Send
This is ridiculous. Closing.
I was born with webbed fish toes. This tiny ad is my only friend:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


Reply locked
This thread has been viewed 1747 times.
Similar Threads
Put Mikalai Zaikin.pdf on internet for download
Download Mikalai Zaikin Notes
Problem while deploying WebService on Tomcat + JWSDP 1.5
Resources for SCWCD
Passed SCWCD 97%
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:44:39.