• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javacaps exam explanation?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I HAVE DOUBTS FOR FOLLOWING Q.S FROM JAVACAPS EXAM 1. WILL ANYONE PLEASE CLEAR THEM FOR ME?
THANKS.
10). What is the result when you compile the 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);
}
}
}
A) Compilation error
B) Runtime error
C) Compile successfully, nothing is printed.
D) Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo

ANSWER IS A. WHY?

11) Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object, which is no more in use.
D) Garbage collector immediately runs when you set the references to null.

ANSWERS ARE A,C. WHY NOT B TOO?
26) Which of the following are correct, if you compile the following code?
public class CloseWindow extends Frame implements WindowListener {
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public static void main(String args[]) {
CloseWindow CW = new CloseWindow();
}
}
A) Compile time error
B) Run time error
C) Code compiles but Frame does not listen to WindowEvents
D) Compile and runs successfully.

ANSWER IS A. WHY?
39) Which of the following statements are true?
A) An inner class cannot be defined as private.
B) Static methods can be overridden by static methods only.
C) Static variables can be called using class name.
D) Non static variables can be called using class name.
ANSWERS ARE B,C. WHY B? STATIC METHODS CANNOT BE OVERRIDDEN BUT HIDDEN BY STATIC METHODS.
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jayu jadhav:
I HAVE DOUBTS FOR FOLLOWING Q.S FROM JAVACAPS EXAM 1. WILL ANYONE PLEASE CLEAR THEM FOR ME?
THANKS.
10). What is the result when you compile the 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);
}
}
}
A) Compilation error
B) Runtime error
C) Compile successfully, nothing is printed.
D) Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo

ANSWER IS A. WHY?

11) Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object, which is no more in use.
D) Garbage collector immediately runs when you set the references to null.

ANSWERS ARE A,C. WHY NOT B TOO?
26) Which of the following are correct, if you compile the following code?
public class CloseWindow extends Frame implements WindowListener {
public CloseWindow() {
addWindowListener(this); // This is listener registration
setSize(300, 300);
setVisible(true);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public static void main(String args[]) {
CloseWindow CW = new CloseWindow();
}
}
A) Compile time error
B) Run time error
C) Code compiles but Frame does not listen to WindowEvents
D) Compile and runs successfully.

ANSWER IS A. WHY?
39) Which of the following statements are true?
A) An inner class cannot be defined as private.
B) Static methods can be overridden by static methods only.
C) Static variables can be called using class name.
D) Non static variables can be called using class name.
ANSWERS ARE B,C. WHY B? STATIC METHODS CANNOT BE OVERRIDDEN BUT HIDDEN BY STATIC METHODS.


Hi,
#10. You invoke method throwDemo(), which belongs to class ThrowsDemo() but you did not instantiate ThrowsDemo object in main()!
#11. GC cannot be forced. We can provide code to signal to GC that an object is ready for GC but we cannot tell GC to reclaim memory immediately when we like so.
#26. You did not setup a Frame.
#39. Here is the rules:
a) It is illegal for a subclass to hide an instance method (a non-static method) of its superclass with its own static method of the same signature. This will result in a compiler error.
b) It is illegal for a subclass to override a static method of its superclass with its own instance method of the same signature. This will also result in a compiler error.
The B) answer definitely rules out overridden and hiding aspect of mix access (static vs. non-static).
Hope that helps. Am I missing anything?
Regards,
Lam
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jayhu, Lam ...
Lam, the compile error in Q.10 is not due to a lack of an instantiation. The <code>throwsMethod()</code> is static and therefore accessible to <code>main()</code>.
A compile error occurs in Q.10 because <code>throwMethod()</code> does not declare that it throws an exception; the signature should be <code>static void throwMethod() throws IllegalAccessException { // method code }</code>
See JLS�11.2


For each checked exception which is a possible result, the throws clause for the method (�8.4.4) or constructor (�8.8.4) must mention the class of that exception or one of the superclasses of the class of that exception.


Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited April 14, 2001).]
 
Lam Thai
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jane Griscti:
Hi Jayhu, Lam ...
Lam, the compile error in Q.10 is not due to a lack of an instantiation. The <code>throwsMethod()</code> is static and therefore accessible to <code>main()</code>.
A compile error occurs in Q.10 because <code>throwMethod()</code> does not declare that it throws an exception; the signature should be <code>static void throwMethod() throws IllegalAccessException { // method code }</code>
See JLS�11.2
Hope that helps.


Thanks Janes - I stand corrected.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem in #26 is that the class does not implement ALL the methods in the WindowListener interface.
 
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic