Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract class

 
swapnil paranjape
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me out :

Which of the follow statements is true.

a. An anonymous class can be declared abstract.
b. A local class can be declared abstract.
c. An abstract class can be instantiated.
d. An abstract class is implicitly final.
e. An abstract class must declare at least one abstract method.
f. An abstract class can not extend a concrete class.


ans is :b

i thought ans should be b and e.

why e is not the ans?
if we dont have any abstract method in the abstract class then whats the use of making class abstract(if all the methods have their implementation)
 
Oscar Gonzalez
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To have such a class it's probably stupid, but that doesn't mean that is not legal.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An abstract class is not required to have an abstract method in it.

Any class that has an abstract method in it or that does not provide an implementation for any abstract methods declared in its superclasses or implemented interfaces must be declared as an abstract class.
 
Gianfranco Cecconi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The rule of thumb I use about abstraction and the relationship between classes and their methods is "Only abstract class can have abstract methods": once this is verified, everything else is possible. Hope I'm not wrong :-)
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e is not correct because a class can simply be declared abstract even if it contains no methods.
 
Kishore Balla
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Keith Lynn:
e is not correct because a class can simply be declared abstract even if it contains no methods.


Example for above is javax.servlet.http.HttpServlet
[ May 30, 2006: Message edited by: Kishore Balla ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic