• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

a question from javacross

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class that doesnot have an access modifier in its declaration is visible to which of the following

1]. objects within the same package

2]. objects in all the packages

3]. only objects that have been instantiated

4]. All objects within the program

the answer is 3.can anybody give an explanation for that,why not 1.a class with default access modifier is visible within same package right!
thanx in advance
aswini
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah I am also Thinking the answer would be 1, because to get visible No need to Instantiate isn't it?
can anybody put some lite on this?......
Siva.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Choice 1 may be right if it is given as
other "classes" within the same package.
But in the real sense a class can be accessed only through an instantiated OBJECT!
GoodLuck!
 
Sivalingam Sivasuthan
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Priya Kannan,
Why Do we need an instantiated OBJECT to access a Static member of that Class?.
Siva

Originally posted by Priya Kannan:
Hi,
Choice 1 may be right if it is given as
other "classes" within the same package.
But in the real sense a class can be accessed only through an instantiated OBJECT!
GoodLuck!


 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also this object is only available in that package and only to subclasses of that package no where else.
 
Priya Kannan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Siva,
Agreed!Missed to mention that.So chill!But actually, I think the catch in this question is not whether the static or non static members of the class in question can be accessed with or without an object...but when class members are accessed via an object,it gotta be instantiated.
Hey Val...I'm definetly not advocating for the class's visibility outside the package whether the damned object is instantiated or not!So you too,chill!
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siva,
The question that started this discussion was mentioning 'Access Modifier' and you brought 'static' into the picture. 'Static' is only a modifier not a 'Access Modifier'. Access Modifiers are 'public, protected and private' (I wonder why 'package' (default) isn't mentioned in RHE book).
~Sri~

Originally posted by Sivalingam Sivasuthan:
hi Priya Kannan,
Why Do we need an instantiated OBJECT to access a Static member of that Class?.
Siva


 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
can anyone explain me all the options.
Iam trying hard but I think I will take time to settle down with these concepts.
Thankyou.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi siva,
I read the reply of Sri.(It is as following)
Siva,
The question that started this discussion was mentioning 'Access Modifier' and you brought 'static' into the picture. 'Static' is only a modifier not a 'Access Modifier'. Access Modifiers are 'public, protected and private' (I wonder why 'package' (default) isn't mentioned in RHE book).
~Sri~

Sri, static is also a Access Modifier. I have confirmed it in Java language specification.
The default (if nothing specified) is also a Access Modifier and it is mentioned in RHE book.
I think the answer must be 1 and not 3.
regards
nidiya

 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question is poorly worded.
I don't mean to rag on the JavaCross exam, but I didn't find the questions to be up to par. A lot of typo and poorly worded exam questions.
I would recommend using JQ+ or Marcus Green's exams.
-Peter
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic