• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Static class  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have some confusion related to static class. I have read in a book that

A static nested class is not an inner class, it's a top-level nested class.



but we code it like this...



Nested is defined within BitOuter, then how can one say that it is not an inner class.

 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it shares absolutely no relationship with it's enclosing class. It is treated (instantiated) as if it was a top level class.
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They don't consider it an inner class because inner classes share a "special" relationship with its outer class, because you need a live instance to instantiate it, whereas with a static class you don't. It's scope is nested but its access it top-level.

 
Bartender
Posts: 1970
57
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Defination:


What is an inner class ?

A Non Static Nested class is known as an inner class.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static inner class cannot be an inner class in its true meaning because an inner class would closely relate, have a special relationship, to the instances of the outer class created; and it is evident that static has nothing to do with instances in particular.
 
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quote from Effective Java

Each instance of a nonstatic member class is implicitly associated with an
enclosing instance of its containing class. Within instance methods of a
nonstatic member class, you can invoke methods on the enclosing instance
or obtain a reference to the enclosing instance using the qualified this construct



A static nested class does not have access to the enclosing instance.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Muhammad Ali Khojaye wrote:quote from Effective Java

Each instance of a nonstatic member class is implicitly associated with an
enclosing instance of its containing class. Within instance methods of a
nonstatic member class, you can invoke methods on the enclosing instance
or obtain a reference to the enclosing instance using the qualified this construct



A static nested class does not have access to the enclosing instance.



That would indeed be the most appropriate explanation.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!