Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Inner classes (4/20/99)

The JavaWorld experts answer your most pressing Java questions -- every week

  • Print
  • Feedback

QIs it possible to declare a class inside another class and to have the inner class access the private variable of the main class?

A Certainly! Java 1.1 introduced the concept of inner classes to the Java language. Here's an example of an inner class accessing a private data member of an enclosing class:

public class OuterClass {
   private static String hiding = "You can't see me!";
   public static class InnerClass {
      public static void showMe() {
         System.out.println(hiding);
      }
   }
   public static void main (String args[]) {
      InnerClass.showMe();
   }
}


When run, this application will print out "You can't see me!"

  • Print
  • Feedback
What is Tech Briefcase?
TechBriefcase is a new, free service where IT Professionals can Search, Store and Share IT white papers and content like this. Learn more
Bookmark content
Speed up your research efforts with content across the web.
Search and Store
Find the white papers you need. Create folders for any topic.
View Anywhere
Open your briefcase on your iPhone, tablet or desktop. Share with colleagues.
Don't have an account yet?

Resources