aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Pls help- write a code with anonymos class, indicate  with a comment line in the code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Pls help- write a code with anonymos class, indicate  with a comment line in the code" Watch "Pls help- write a code with anonymos class, indicate  with a comment line in the code" New topic
Author

Pls help- write a code with anonymos class, indicate with a comment line in the code

kaffo lekan
Ranch Hand

Joined: Feb 13, 2001
Posts: 42
Hello Please, write a code for me showing the use of an anonoymos class , please indicate with comment showing it.
Vegad Arvind
Ranch Hand

Joined: Jan 10, 2001
Posts: 42
Hi,
Here the code and explanation from Exam cram mock test

In the following code for a class in which methodA has an inner class
1. public class Base {
2. private static final int ID = 3; //final variable
3. public String name; // public variable
4. public void methodA( int nn ){ //nn is arg not final
5. final int serialN = 11; //final variable
6. class inner { //innner class start here
7. void showResult(){
8. System.out.println( "Rslt= " + XX );
9. }
10. } // end class inner
11. new inner().showResult();
12. } // end methodA
13. )
which variables would the statement in line 8 be able to use in place of XX? [Check all correct answers]
A) The int ID in line 2
B) The String name in line 3
C) The int nn in line 4
D) The int serialN in line 5
Answer
A is correct: The int ID in line 2
B is correct: The String name in line 3
D is correct: The int serialN in line 5
Explanation Answers a, b, and d are correct. Answers a and b are correct because inner classes can access any static or member variable in the enclosing class. Answer d is correct because, although it is a local variable, it is declared final. Answer c is incorrect because the local variable nn is not declared final. This special usage of the keyword final causes the compiler to provide storage for this variable in a permanent location. This is necessary because an inner class object created in a method may outlive the method.

Hope it will help

Best Regards
Avi
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Kaffo,
I am not sure what question Vegad was answering, but here is an example of using an anonymous class to override a single method. This is most useful when writing UI code and using listener adapters.

Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pls help- write a code with anonymos class, indicate with a comment line in the code
 
Similar Threads
static objects
NX:Java Convention Style- Comments
Reflection problem
Problem with Javascript
Stack ADT help