• Post Reply Bookmark Topic Watch Topic
  • New Topic

anonymous inner class problem  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TestCase test= new MoneyTest("simple add") {
public void runTest() {
testSimpleAdd();
}
};

First of all this not related to JUnit . I am not getting this code . It is refered as a anonymous inner class in the tutorial .

Other code related to this is there is a classs MoneyTest that extended a class TestCase of JUnit & that has a method testSimpleAdd() .

Thanks .
[ January 11, 2005: Message edited by: rathi ji ]
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
TestCase test= new MoneyTest("simple add") {
public void runTest() {
testSimpleAdd();
}
};



In this code, no doubt an annonymous inner class is being created. If MoneyTest is an abstract class, then your annonymous inner class 'extends' this abstract class. If MoneyTest is an interface, then your annonymous inner class implements this interface. Now what exactly is MoneyTest in your case? Is it a concrete class or an abstract one? If its a concrete class then you are just extending that class here. Does this help?
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
TestCase test= new MoneyTest("simple add") {


But I have my own doubts about the syntax of this constructor!
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. The sytax is fine. I tried it out with a small piece of code myself and this code is fine. So the explanation that I have given should hold good.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As you told that this anonymous inner class is a sub class of MoneyTest .



Are both code are similer .... what is happening .... i am not getting anything ???

please help me ....

thanks a lot
[ January 11, 2005: Message edited by: rathi ji ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Now I have got this code .
test a reference variable of TestCase class & that have reference of a object of an anonymous class that is sub class of MoneyTest class .

but now my doubt is object of this anonymous class is getting created so constructor of this class will be called , but this class doesn't have any consturctor that is taking string as a parameter ...

please clear my doubt .

thanks a lot .
[ January 11, 2005: Message edited by: rathi ji ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!