This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why a class declared as Abstract, cannot have any abstract method declaration? 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 "Why a class declared as Abstract, cannot have any abstract method declaration?" Watch "Why a class declared as Abstract, cannot have any abstract method declaration?" New topic
Author

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

Muhammad Yasir Ch
Greenhorn

Joined: Oct 05, 2007
Posts: 27
Why a class declared as Abstract, cannot have any abstract method declaration?


SCJP 6- 86%
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Abstract classes can declare abstract methods. That's what they are for after all Do you have any concrete example of your problem ?


[My Blog]
All roads lead to JavaRanch
Mai Vala
Greenhorn

Joined: Mar 31, 2010
Posts: 14
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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Mai Vala
Greenhorn

Joined: Mar 31, 2010
Posts: 14
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.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

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


Couldn't understand the OP's question!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

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


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

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.

SCJP6.0,My blog Ranchers from Delhi
 
jQuery in Action, 2nd edition
 
subject: Why a class declared as Abstract, cannot have any abstract method declaration?