This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 9708
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...
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic