• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

INNER CLASS

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which are a part of a correct inner class declaration or a combined declaration and instance initialization

A. private MyInner {
B. new SimpleInterface() {
C. new ComplexInterface(x) {
D. private final abstact class C
E. new ComplexClass() implements SimpleInterface
MY ANS ARE:A,B,C
NOT SURE IF OPTION C IS CORRECT,PLS CORRECT ME IF I AM WRONG

2: What snippet can be a part of a declaration of an inner class: (select all)
A. private MyInner {
B. new myInner() extends OtherClass {
C. static class MyInner {
D. abstract class MyInner {
MY ANS ARE:A,C,D
Which are valid declarations :
a. private class A
b. class X extends Y { // Note the {
ANS ARE:A,B
I AM APPEARING FOR THE EXAM BY THIS SATURDAY
HELP PLS
THANX
SHERIN
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sheri!
If �combined declaration and instance initialization� means that class is anonimous (and I think so)
than
C) new ComplexInterface(x) {
is incorrect, because anonimous inner classes cannot have a constructor, which could take parameter x.
If option C were coded as
C) new ComplexInterface() {
- it would be correct
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sheri;
Here is my answers:
Which are a part of a correct inner class declaration or a combined declaration and instance initialization
A. private MyInner {
B. new SimpleInterface() {
C. new ComplexInterface(x) {
D. private final abstact class C
E. new ComplexClass() implements SimpleInterface
Answers: B,C
A is incorrect since it misses the keyword class in the declaration.
2: What snippet can be a part of a declaration of an inner class: (select all)
A. private MyInner {
B. new myInner() extends OtherClass {
C. static class MyInner {
D. abstract class MyInner {
Answers: C,D

Thanks,
Erin
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mapraputa Is:
Hi sheri!
If �combined declaration and instance initialization� means that class is anonimous (and I think so)
than
C) new ComplexInterface(x) {
is incorrect, because anonimous inner classes cannot have a constructor, which could take parameter x.
If option C were coded as
C) new ComplexInterface() {
- it would be correct


Hi,
if the annonymous class is extending from any class which has a constructor then the ans C would be correct.here he didn't mention that complexinterface is an interface or a class.ofcourse there is a clue that it can be an interface but we are not sure whether that is extending from class or interface in which case I would say C is also correct ans.
geetha

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi geetha,
But anonymous classes, by definition, dont have a constructor or a name.
If the class extends another class which has a constructor, the inner class is not anonymous ..am I right? or am I missing something?
could you give an example ?
or,could you tell me what modifications are to be made to convert the foll into an anonymous class like you said, extending from class father, and without a name..

thanks in advance,
Ramani.


 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ramani,
I played with your code and think this is an example of using an anonymous class (please let me know if I'm wrong).
I changed the original to use main() instead of Applet and I had to put a call in the 'father' constructor to access method() (is there a way to directly invoke a parent method from an Anonymous class? I could not find any code examples.)

 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic