• 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

A class defined within a method

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Kasey Tritt
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That certainly helps!
Thanks, Corey.
 
reply
    Bookmark Topic Watch Topic
  • New Topic