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

declaration and initialization

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which are true about combined declaration and initialization.
A. private class C ---false no {}
E. private class Myclass extends Otherclass - ---for inner class it is ok but no braces{}

Which best describes the characteristics of a well encapsulated class?
-Methods are private.--false
-Member variables are private.--false
-Methods are private or protected, and members variables are public.--false
-Methods are public and member variables are default or private.-true
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which are true about combined declaration and initialization.
A. private class C ---false no {}
E. private class Myclass extends Otherclass - ---for inner class it is ok but no braces{}
This is impossible to answer as written - "which are true" makes no sense because none of the answers actually say anything. Also neither answer has anything to do with initialization, so I can't tell what the question is actually supposed to be about.

Which best describes the characteristics of a well encapsulated class?
-Methods are private.--false
-Member variables are private.--false
-Methods are private or protected, and members variables are public.--false
-Methods are public and member variables are default or private.-true
I disagree. There's no reason that all methods need to be public. And it's arguable whether default access should be allowed - any variable access outside the class weakens encapsulation, although default access is not too bad. The second option is good, as it doesn't place needless restrictions on methods, and doesn't allow default access for varables.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that second option is correct because all the method variables have their scope restricted to the method in which they are defined and they can be accessed outside the method so will it be wong if I say the method variables are private?
Correct me if I am wrong !!
Thanks,
Milind
 
josephine chen
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are the following class declarations correct?
private class C --- false no {}
private class Myclass extends Otherclass - ---for inner class it is ok but still has no {}
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Milind - yes, the second option is good.
Shan - you are correct that neither one is a complete declaration, since braces are missing. And they both must be inner classes, or at least nested classes, in order for "private" to be a legal modifier. This is true of the first just like the second; I don't know why you treat them differently.
 
reply
    Bookmark Topic Watch Topic
  • New Topic