Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract inner classes

 
Rachana Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,

could anyone please tell me how is an abstract inner class implemented by other classes.
some sort of code snippet would be really helpful as iam very confused.

Thanks in advance.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to write something yourself, compile and run it. If it does not work post it - for discussion and help. You will learn much better that way.
 
Devender Thareja
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you go:

public class SychTest
{
abstract public class InnerTest
{
abstract public void test();
}

private class InnerTest1 extends InnerTest
{
public void test()
{
return;
}
} ;
InnerTest1 test1= new InnerTest1();

}
 
Rachana Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer.

Just go through the code and my doubt is why does the compiler show error when we don't extend the outer class and just want to extend the outer.inner in the TestInner.

 
Rahul Krishan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While extending the inner classes, we have to explicitly set some relation between the extending class and the outer class for this inner class. So, the issue is resolved when we go by the second approach. The other approach could be

public class Test{
class TestInner extends Outer.Inner{
TestInner(Outer o){
o.super();
}

public void show(){
System.out.println("in the test1 class!!");
}
}

public static void main(String ar[]){
Test test=new Test();
Outer oo = new Outer();
Test.TestInner in=test.new TestInner(oo);
in.show();
}
}

Hope this solves the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic