• 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

Why a class declared as Abstract, cannot have any abstract method declaration?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why a class declared as Abstract, cannot have any abstract method declaration?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstract classes can declare abstract methods. That's what they are for after all Do you have any concrete example of your problem ?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,abstarct claases can declare both abstract and non abstract methods.
In fact you can only declare methods in abstract classes but you can't define them in abstract classes.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mai Vala wrote:In fact you can only declare methods in abstract classes but you can't define them in abstract classes.


only, if the method is abstract . as you said abstract class can have non-abstract method[which has the body] right?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad Yasir Ch wrote:Why a class declared as Abstract, cannot have any abstract method declaration?



If my understanding is correct are you referring to the following scenario ?



The class above is abstract but does not define any abstract methods in it.
 
Mai Vala
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:only, if the method is abstract . as you said abstract class can have non-abstract method[which has the body] right?



Yes, if the method is non abstract then you have to follow the method declaration with curly braces.
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad Yasir Ch wrote:Why a class declared as Abstract, cannot have any abstract method declaration?



Couldn't understand the OP's question!
 
Ranch Hand
Posts: 400
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad Yasir Ch wrote:Why a class declared as Abstract, cannot have any abstract method declaration?


What i understand from your question: Why a class declare as abstract if it does not have any abstract method? right?

Well, we declare a class abstract when we want to give some ready made behavior to a child.

The child will have choice to override their own behavior or just simply inherit from father, this is something that we cannot achieve with *Interfaces*.

Lets say the: We have a Father class Animal for all the animals following listed two behaviors of an animal.
1. fly.
2. sound.

Each Animal can sound, but only bird animals can fly...

Check out the following example.


[Edit: more example]

Abstract class is just like a concept where its child classes are the real things. Similarly Animal itself is not something that exist in real, the Animal cat,duck, dog and so on are real objects...

Therefore, Animal class in above example is an abstract because animal is no more than a concept no one can create an object of Animal in reality Cats, Dogs, Ducks, and etc exists...


Hope this helps

Minhaj
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muhammad Yasir Ch wrote:Why a class declared as Abstract, cannot have any abstract method declaration?



i think you are talking about this.......



the above code will compile fine....as the abstract class can have both abstract and non abstract methods.
 
reply
    Bookmark Topic Watch Topic
  • New Topic