Wrox Programmer Forums
|
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2003, 12:47 AM
Registered User
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Nested Classes

I was hoping somebody could help me with regards to understanding nested classes. For the most part, I understand the access attributes among enclosing, inner, and static classes however, I am having trouble with one. It's shown in the diagram on p.210 in my book that instance members of a non-static nested class can access static members of a fellow static nested class within the same top level class. Yet when I try to demonstrate this with a dummy program, I get a 'cannot resolve symbol' error because the static variable in the static nested class is not recognized in the non-static class from which I attempt to access it. Just so it's clear, I'm not creating an object of the static class in the non-static one first, and then, using the dot operator, try to gain access to the static variable, i.e. staticNestedClassObject.staticVariable -- rather, i'm trying to use the variable directly in the non-static class by accessing it simply as staticVariable.

I was hoping somebody could enlighten me if i've miss understood something and perhaps post a small snipet of code for me to look at that would make things clearer.

Thanx in advance -- S.N.
 
Old August 11th, 2003, 05:21 AM
Registered User
 
Join Date: Jun 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You cannot access staticVariable by just using the unqualified name. The compiler will be looking for staticVariable in the current nested class or in the enclosing class.To identify staticVariable properly you must qualify it with its class name e.g. ClassName.staticVariable.
 
Old October 11th, 2003, 01:49 PM
Authorized User
 
Join Date: Oct 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mrafaqi Send a message via Yahoo to mrafaqi
Default

hi,
 staticare members which are called class members, so they do not require object to access them.
private are class private members so a private member can not accessed any where out side class.
public it is the most loose attribute which allows that member to be accessed from anywhere.
protected only accessed by a child class.

if you want to access a static member, you can access it without the help of object of class.

in nested class if the inner class is static so it may be considered as a seperate class, so not referenced of outer class requires.
above is same like main which is an inner static member in a outer class.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Using classes seymour_glass C# 1 April 26th, 2007 10:18 PM
classes dhoward VB.NET 2002/2003 Basics 2 November 8th, 2006 10:35 AM
About Classes. wdw BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 29th, 2005 08:46 AM
Finding Nested Classes hard to grasp pilgrim BOOK: Beginning Java 2 2 February 3rd, 2005 11:17 AM
Classes CodeMonkeys C# 3 August 18th, 2004 11:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.