GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 412 of 502    Print  
What is the purpose of an anonymous class and what is the realtime usage of this.

  
Total Answers and Comments: 1 Last Update: August 03, 2007     Asked by: nsinha 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sujatham
 

Classes are usually first defined and then instantiated using the new operator. Anonymous classes combine the process of definition and instantiation into a single step. Anonymous classes are defined at the location they are instantiated, using additional syntax with the new operator. As these classes do not have a name, an instance of the class can only be created together with the definition.

An anonymous class can be defined and instantiated in contexts where a reference can be used (i.e., as expressions that evaluate to a reference denoting an object). Anonymous classes are typically used for creating objects on the fly in contexts such as the value in a return statement, an argument in a method call, or in initialization of variables. Anonymous classes are heavily used to implement event listeners in GUI-based applications.



Above answer was rated as good by the following members:
talktoatish
August 03, 2007 05:42:07   #1  
sujatham Member Since: January 2006   Contribution: 142    

RE: What is the purpose of an anonymous class and what...

Classes are usually first defined and then instantiated using the new operator. Anonymous classes combine the process of definition and instantiation into a single step. Anonymous classes are defined at the location they are instantiated using additional syntax with the new operator. As these classes do not have a name an instance of the class can only be created together with the definition.

An anonymous class can be defined and instantiated in contexts where a reference can be used (i.e. as expressions that evaluate to a reference denoting an object). Anonymous classes are typically used for creating objects on the fly in contexts such as the value in a return statement an argument in a method call or in initialization of variables. Anonymous classes are heavily used to implement event listeners in GUI-based applications.


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

Latest Answer : Yes !! if you are talking about the base and child class relationship then we can drive. ...

Latest Answer : yes they are represented as wrapper classes ...

Latest Answer : A static member class or a static member interface comprises the same declarations as those allowed in an ordinary top-level class or interface. A static member class must be declared as a static member of an enclosing class or interface. Nested ...

Can we declare multiple main() methods in multiple classes.ie can we have each main method in its class in our program?

br />1.what is oracle.2.what is major differenece oracle8i and oracle9i.4.tell me some thing ur self.5.please tell me about oops.6.what is single inheritance.7.what is multiple inheritance.8.can java support 
Latest Answer : 8.can java support multiple inheritance.java support multiple inheritance for interfaces not fro classes25.what is difference between procedure and functions.function returns only one value where as procedure returns more than one value ...
Read Answers (11) | Asked by : rajjava

Latest Answer : No a Class, Method cannot be Garbage collected simply because a class or Method does not have physical exestence in memory and garbage collector is only used for freeing up the memory which only applies to objects not classes or methods.So only objects ...
Read Answers (5) | Asked by : chandu

I want to create two instances of a class ,But when trying for creating third instance it should not allow me to create . what i have to do for making this?
Read Answers (4) | Asked by : chandu

Latest Answer : An interface is a specification of method prototypes. All the methods of interface are public and abstract. They are public because they should be available to third party vendors and they are abstract because their implementation is left for third party ...
Read Answers (11) | Asked by : prakash

I need some more information about interface. For Example there is no any functionality inside the method which is declared in any interface. Then why i want to implement that interface to my class. 2. Statement is an interface. When i say stmt.executeQuery(). I am getting the records in my ResultSet. How it is possible?.. since there is no functionality insid the methods which is declared in Statement Interface. What is happning here?
An idea 

What is the difference between putting a class as abstract or if any of method in class is declared as abstract diference of these two while extending these two types of classes
Read Answers (1) | Asked by : karunakar
Tags : Abstract


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

Microsoft AJAX Library - Anonymous Functions

Anonymous Functions Anonymous functions can be created adhoc and used instead of a named function Although this can hinder readability when the function is more complex you can do this if you don t intend to reuse a function s code In the following example we pass such an anonymous function to Displ
 

SOA Industry Usage

SOA Industry Usage First time usage of SOA tends to highlight the need for semantic interoperability While SOA provides framework for integration of cross Business operations with information flow in real time there is also a major semantic interoperability conflict that is not being addressed dir
 

C++ Pure Virtual Function and Base Class

C Pure Virtual Function and Virtual Base Class In this C tutorial you will learn about pure virtual function declaration of pure virtual function and virtual base class virtual base class and how to implement a virtual base class explained with examples mosgoogle center What is Pure Virtual Function
 

Java and Client Server Models

Java and Client Server Models The Role of Client Servers on the Web Client server models provide the essential mechanisms for working with the Internet In fact most of the World Wide Web is built according to this paradigm In client server models the web browsers run by millions of users are the cli
 

How to Access C++ Class Members

How to Access C Class Members In this C tutorial you will learn how to access Class members dot operator or class member access operator difference between struct and class and  scope resolution operator mosgoogle center It is possible to access the class members after a class is defined an
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

Industry Usage of VoiceXML

Wireless communications tools have a number of disadvantages, and some of these are small screens, weak processing power, and a lack of sufficient input abilities. It is these three factors that have greatly limited the scope of many wireless devices, and it is hoped that VoiceXML will remedy many
 

Using UML with Java

Using UML with Java While Java is not a new language its application for the development of embedded systems is quite new Developers are beginning to take a second look at modeling languages such as UML and many feel it can be a powerful tool in their development arsenal mosgoogle center Introductio
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape