Forums Register Login

Anonymous inner class question

+Pie Number of slices to send: Send
Given the following



Bing b= new Bing(){"Foo";};
Bing b=new KAndBExam1();

Those two are given as correct answers. But when I insert option 3 at comment line,it gives �illegal start of type� error.I don�t know how to correct it.Please share your knowledge on this.
+Pie Number of slices to send: Send
You sure the line isn't something like

Bing b= new Bing(){String s = "Foo";}; ?

You can't just declare a String literal like "Foo" on a line by itself in any type of class (at least none that I'm aware of).

Also no clue what KAndBExam1 is.

You really need to give more of the complete question in order to provide more feedback. (You also mention an 'option 3' which I'm guessing refers to the Bing b = new Bing()... answer?)
+Pie Number of slices to send: Send
Any mindreaders aound here?
+Pie Number of slices to send: Send
Thankyou.I am sorry for lazy to type all options. I got that question from K&B1.4 book Master Exam CD.

Here comes all the options
1) KAndBExam1 b= new Bing("Foo"){};
2)Bing b=new Bing("343"){};
3) Bing b= new Bing(){"Foo";};
4)Bing b=new KAndBExam1(){};
5)Bing b=new Bing.KAndBExam1("Foo"){};

I am very sure about the given third option is like that.Maybe typo mistake by author.

If I include option 3 at insert code line,How can I access that anonymous class variable(String s=�Foo�);Any comments���
+Pie Number of slices to send: Send
how does this bcome the correct answer Bing b=new KAndBExam1(){};

where is that methoed in the bing class.....post the full question please
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 521 times.
Similar Threads
anonymous inner class
Anonymous Inner class from K&B mock exam
Error in MasterExam?
anonymous inner class question
comprehensive exam(kathy/Bert book)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:08:50.