permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous inner class question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Anonymous inner class question" Watch "Anonymous inner class question" New topic
Author

Anonymous inner class question

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
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.
Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
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?)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Any mindreaders aound here?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
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���
shilpa Reddy
Ranch Hand

Joined: Jul 26, 2006
Posts: 42
how does this bcome the correct answer Bing b=new KAndBExam1(){};

where is that methoed in the bing class.....post the full question please
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anonymous inner class question
 
Similar Threads
Anonymous Inner class from K&B mock exam
anonymous inner class
comprehensive exam(kathy/Bert book)
Error in MasterExam?
anonymous inner class question