• 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
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Inner class instantiation

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from enthuware test.

public class TestOuter
{
public void myOuterMethod()
{
// 1
}
public class TestInner { }
public static void main(String[] args)
{
TestOuter to = new TestOuter();
// 2
}
}


Which of the following options correctly instantiates a TestInner object?




Select 2 correct options
a. new TestInner(); at //1

b. new TestInner(); at //2

c. new to.TestInner(); at //2

d. new TestOuter.TestInner(); at //2

e. new TestOuter().new TestInner(); at //1


The correct options given are
a. new TestInner(); at //1
e. new TestOuter().new TestInner(); at //1

I got the first one right.For the other instantiation ,I was searching for an answer to.new TestInner() at //2.

I felt it was kinda misleading to ask for an answer to be placed at //1 and //2 and giving the answers only for //1.May be I misunderstood the question!

Anyway ,my concern is not this qustion..but in the real exam, will there be any ambiguity as to how to answer the question?!

Because you know,I dont want to lose a question just because it has been worded in such a manner.

May be I am reading too much into this ...I dont know!
I just wanted to know if others felt this way or its just me...
With the exam date fast approaching,I might just be panicking!
 
Ranch Hand
Posts: 220
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
relax.. everyone can think differently in some questions. You should practise as much as you can do. But you should always be concentrated for exam traps like syntax...

yes question is true but it can be clear by saying insert independently 1 - 2 position...

for answers A ) is true because you had the outer instance which is enough to create an inner class
for E) you are creating outer instance then the inner class...

 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is a pretty good question...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic