• 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

inner classes

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to use abstract keyword with inner classes?
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<PRE>
class Outer {
abstract class Inner {...}

}
</PRE>
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it true ?
any body please!
Thanks
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tony is right. Just tested the following...
// Javaranch.java
public class Javaranch{
abstract class AbsInner{
abstract int GetVal();
}// end of AbsInner
class Inner extends AbsInner{
private int j = 20;
int GetVal (){
return j;
}// end of GetVal
}// end of Inner
public static void main(String[] args){
Javaranch myOuter = new Javaranch();
Inner myInner = new Javaranch(). new Inner();
System.out.println("hello :" + myInner.GetVal());
}// end of main
}// end of Javaranch
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yojana,
Yes, you may also declare an inner class to be abstract if it is not complete and would want to prohibit the client from instantiating it.
Regards,
Milind
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tony is correct. In practical terms, I have never seen a use for an abstract inner class. Anyone?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question has come up a few times before, and I don't think anyone's come up with a practical use for an abstract inner class, though they certainly can exist. Some more thoughts on the matter can be found here.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jim, All,
Here is my understanding about use of extending classes in a local method.
A typical use for this feature could be
-To create customized objects from within a method
-Hide the details about creation and implementation of these objects
In other words, I call a method and I get back an object which implements a certain
interface. I get different types of objects, each in a different state depending
upon the method parameters. Code outside the method knows nothing except the
object it gets back.
This is encapsulation and polymorphism down to the method level.
Using non local member classes will expose the code to other members but will still limit the visibility to the enclosing class.
Similar concept could apply to inner classes being discussed in this thread.
I hope it makes sense. Feel free to correct me.
An example follows.

[This message has been edited by rajsim (edited June 20, 2000).]
reply
    Bookmark Topic Watch Topic
  • New Topic