• 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

access modifier for an abstract class

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

Which of the following access modifiers can be supplied for the constructor of an abstract class ?
(Mark 3)
Options :

a . public
b . protected
c . private
d . default
e . friendly
f . No access modifier

Answer abc

I have 2 questions:-
1) why is f not correct?
2) i thought if the constructor of the abstract class is marked private then the subclass would not compile as the call to super() would fail. However, one can have one constructor marked private and others public/protected/No access modifier(default) and call those constructors which are not marked private.

However, feel that f has a better case than c.
Please suggest.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i feel deault and no modifier answers are redundant.and if given both should be correct
 
Ranch Hand
Posts: 111
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Swarna,

Actually answer is abcd.

Abstract class is not only used for subclassing but you can put some static methods in that and it can serve as a factory utility class.

Regards,

Abdul Mohsin
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"default" (as a word) is not an access qualifier. What is known as "default access" (that is package access) is specified by supplying no access modifier at all.
[ April 30, 2007: Message edited by: Barry Gaunt ]
 
Abdul Mohsin
Ranch Hand
Posts: 111
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right actually I got confused with "default".
abcf are the correct answers

Regards,

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

"default" (as a word) is not an access qualifier. What is known as "default access" (that is package access) is specified by supplying no access modifier at all.


The question itself is ambiguous, you'd better forget it.

"default" as a word is of course not a modifier. But when I follow the makers of this test like a computer, I would say that f is false the same way, because:


wouldn't compile either

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

simply misleading...
There in not token in Java(in other languages too perhaps) that is made of more than one word (where spaces are delimiters). Its name is token by its nature.

Treating "No access modifier" as modifier is no more than a fun.
"No access modifier" itself says the accessibility is default (without any)
access modifier of course.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

In my view, abstract class constructor cannot be private.
it can be protected, public and no modifier.
abstract constructor can be called only from its subclasses, when a private constructor is exists in abstract class, the sub class is restricting to call the abstract class's constructor since it is private.

Can any one clarify this, am I right or wrong?

Thanks in advance for clarification.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by madhu v pe:
Hi all,

In my view, abstract class constructor cannot be private.
it can be protected, public and no modifier.
abstract constructor can be called only from its subclasses, when a private constructor is exists in abstract class, the sub class is restricting to call the abstract class's constructor since it is private.

Can any one clarify this, am I right or wrong?

Thanks in advance for clarification.



A private constructor in an abstract class can be called by other overloaded constructors in the same abstract class. Therefore, if the overloaded constructors can be called by the subclass constructor, everything is OK!
 
madhu v pe
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnaks Yeming,

you are good at construstor overloading
I have tried that, private also can be used.
In such case answers for the below question[posted in this thread] should be

a,b,c,f

what you say?



Thanks
 
Oh. Hi guys! Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic