This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access modifier for an abstract class

 
swarna dasa
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • 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.
 
raj malhotra
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i feel deault and no modifier answers are redundant.and if given both should be correct
 
Abdul Mohsin
Ranch Hand
Posts: 111
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right actually I got confused with "default".
abcf are the correct answers

Regards,

Abdul
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • 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.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • 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.
 
madhu v pe
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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.
 
Yeming Hu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic