Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Beginning Java
Static nested class
Vlada Den
Ranch Hand
Posts: 32
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi!
Here is the code:
public class StackOfInts { private static class Node { int item ; Node next ; } private Node top ; private void push( int N ) { Node newTop ; newTop = new Node() ; newTop.item = N ; newTop.next = top ; top = newTop ; } public int pop() { int topItem = top.item ; top = top.next ; return topItem ; } public boolean isEmpty() { return ( top == null ) ; } }
My question is: what is the advantage of using a static nested class here?
Thanks!
Vlada
Layne Lund
Ranch Hand
Posts: 3061
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The nested class implies that there is some kind of relationship with the outer class. In this case, the StackOfInts class uses the inner Node class to store the internal linked list.
Layne
Java API Documentation
The Java Tutorial
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Java Stack program
Help with delete() method for linked list
How to create a hierarchy using the following xml file
Modified singelton pattern
evaluate the expression
More...