wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A class defined within a method 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 "A class defined within a method" Watch "A class defined within a method" New topic
Author

A class defined within a method

Kasey Tritt
Greenhorn

Joined: May 02, 2002
Posts: 15
What is really meant by the term "a class defined within a method"? This term is sometimes used in the exam.
Definitions
Local Classes are specific to a block of code. Their visibility is only within the block of their declaration.
Anonymous classes are classes which have no name. They combine the process of definition and instantiation into a single step.
Does anyone know the term "a class defined within a method" refers to a local class or anonymous class or both?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Kasey Tritt:
Does anyone know the term "a class defined within a method" refers to a local class or anonymous class or both?

A class defined within a method could be either a local class or an anonymous class. Here is an example where one of each is defined within a method:

You see, both local classes and anonymous classes can be defined within a method. However, in general, when someone is referring to a class defined within a method, I would presume their talking about a local class, which is the first example.
I hope that helps,
Corey


SCJP Tipline, etc.
Kasey Tritt
Greenhorn

Joined: May 02, 2002
Posts: 15
That certainly helps!
Thanks, Corey.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A class defined within a method
 
Similar Threads
Confusion about Inner Class Classifications
Anonymous class....
Nested class, inner class question
Anonymous Class
Inner class