Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

inner class can we restrict?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hi
i wann to know can we restrict creation of inner classes not more than n number of times?
eg:
class outer
{
int x;
void showx()
{
System.out.println(x);
}
class inner
{
int y;
void showy()
{
System.out.println(y);
showx();
}
}
}
now i know i can create any no. of inner class, can we restrict?
i don't know whether i'm reaching u !!!
thanx
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You can create any number of inner classes.
we cannot restrict
Prabu.U
------------------
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by KESAVAN RAMANUJAM:

hi
i wann to know can we restrict creation of inner classes not more than n number of times?
eg:
class outer
{
int x;
void showx()
{
System.out.println(x);
}
class inner
{
int y;
void showy()
{
System.out.println(y);
showx();
}
}
}
now i know i can create any no. of inner class, can we restrict?
i don't know whether i'm reaching u !!!
thanx


Actually there is a way to design your Outer and Inner class to restrict the number of inner classes that are created. Remember an Outer and Inner class share a special relationship, the can access and use each others private members! If you define all the constructors of the Inner class to be private, only the outer class (and the inner class) can create an instance. Once you do this, you create a method(s) in the Outer class to create instances of the inner class and have a static variable in the outer class which counts the number of inner classes. At this point you can now restrict the number of innerclasses created regardless of the number of outer classes that are created!
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic