aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes access modifier for an abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "access modifier for an abstract class" Watch "access modifier for an abstract class" New topic
Author

access modifier for an abstract class

swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
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

Joined: Feb 22, 2007
Posts: 285
i feel deault and no modifier answers are redundant.and if given both should be correct
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

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


Regards, Abdul Mohsin
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"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 ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Abdul Mohsin
Ranch Hand

Joined: Apr 26, 2007
Posts: 111

Right actually I got confused with "default".
abcf are the correct answers

Regards,

Abdul
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
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

Joined: Feb 28, 2007
Posts: 1707
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.


cmbhatt
madhu v pe
Ranch Hand

Joined: Apr 21, 2007
Posts: 100
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

Joined: May 14, 2007
Posts: 37
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!


Best Wishes,<br /> Yeming
madhu v pe
Ranch Hand

Joined: Apr 21, 2007
Posts: 100
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: access modifier for an abstract class