• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

instantiate objects in inner class in their methods. see how and why?

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Ans: a and d
Why b is wrong???

always loving
aruna
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
B is a static class and therefore does not need an instance of A to be created.

Mark
 
Aruna Agrawal
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it does not need is fine.. but what harm is there if i give it..why compiler complains.. compiler is surely cheating in this case..
similar analogy : to access static method we dont need a object. but if u call on object its fine..

awaiting justice
aruna
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey
There is no such thing as a static class ..The static modifier just says that its a static member of the outer class. AND it can be acessed without an instance of the outer class!!!

class A{
static class B{}
}
class test
static public void main(Sring ar[])
{
A.B x=new A.B();
}
There is no instance of the outer class here the new apllies to the inner class which is being acessed thru the outer
Cheers
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Aruna,


why compiler complains.. compiler is surely cheating in this case..



I dont think compiler complains about having a statement as
"new TestClass().new B(); "

I guess the question is quite vague. It should ask as
select 2 appropriate options
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



Cheers,

Si.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic