There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
inner class


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Caliraj's Avatar
Senior Member with 145 posts.
 
Join Date: Mar 2006
Experience: Intermediate
20-Dec-2006, 05:47 AM #1
inner class
Hi chicon,
thanks for the mail.I also have a doubt about the types of inner classes.Some text books also refer them as Nested class while some tell that nested class, anonymous class,static member class and non -static member class are the types of the inner classes.Im totally confused about it.Could you clear this?
Chicon's Avatar
Computer Specs
Distinguished Member with 6,541 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
20-Dec-2006, 06:44 AM #2
1° Difference between a nested class and an inner class :

Excerpt from this page
Quote:
Terminology : Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are simply called static nested classes. Non-static nested classes are called inner classes.
2° Difference between local and anonymous inner classes :

Excerpt from this page
Quote:
There are two additional types of inner classes. You can declare an inner class within the body of a method. Such a class is known as a local inner class. You can also declare an inner class within the body of a method without naming it. These classes are known as anonymous inner classes. You will encounter such classes in advanced Java programming.
3° Summary on this page

Hi Caliraj,

You should browse more often the Java tutorial from the site of the Java creator :
http://java.sun.com/docs/books/tutorial/java/index.html .
There are too small exercices you may try to check your knowledge.

__________________
for ( ; ; ) ;

Examinations time is coming, take a Java beta exam and get a belt !
Caliraj's Avatar
Senior Member with 145 posts.
 
Join Date: Mar 2006
Experience: Intermediate
21-Dec-2006, 02:06 AM #3
static nested classes
Hi,
Thanks for replies .I have started to work on the nested classes.But as they say, once you start working on anything, you also tend to come across various errors/challenges ...Here is my program below :
class static_innerdemo
{
private int a=10;
static class iner
{
void methin()
{
int b=a*10;
System.out.println("Answer is "+b);
}
}
void methout()
{
static_innerdemo.iner obin=new static_innerdemo.iner();
obin.methin();
}
public static void main(String args[])
{
static_innerdemo obout=new static_innerdemo();
obout.methout();
}
}

The advantage of nested class is that it can access members/variables of the top class even if they are Private.But I get an error.Is it because that the variable 'a' of the top class is not static?
Chicon's Avatar
Computer Specs
Distinguished Member with 6,541 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
21-Dec-2006, 04:28 AM #4
Quote:
Originally Posted by Caliraj
... Is it because that the variable 'a' of the top class is not static?
Yes !
Caliraj's Avatar
Senior Member with 145 posts.
 
Join Date: Mar 2006
Experience: Intermediate
21-Dec-2006, 05:37 AM #5
anonymous class
Hi Chico,
Sorry to bother you much ....I was not bale to get proper examples for anonymous classes.Moreover the sun site syas that any inner class within a method body without a name is an anonymous class.But if there is a class outside the method body without a name, it can also be called as an anonymous class I guess...could you recommend a site with apt examples ???
thanks once again
Chicon's Avatar
Computer Specs
Distinguished Member with 6,541 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
21-Dec-2006, 06:43 AM #6
There is a complete example fully described step by step on this page (The Essence of OOP using Java, Anonymous Classes).

Also, I suggest you to have a look on this page and followings.

I can't better explain.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:49 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.