Could not an abstract class be extended (inherited from) in Java?

Should a class have an abstract keyword before it? Or do you need to have unrealized (abstract) methods? Can any normal class propagate?

+5
source share
7 answers

Can any normal class propagate?

Yes :) If it does not have a final modifier.

+4
source

Yes, all methods that are not final (static are also slightly different from the rest) can be overridden if the class itself is not declared final. Abstract methods are used only if you do not provide any implementation in the base class.

+4
source

, abstract, abstract , , , .

AbstractClass abs = new ChildClass();
+2

, . , . ,

DifferentString extends String

public String toString()
{
    return "Something different";
}

, .

:

http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html

+1

, , , , , , .

+1

, , .

class Foo {
    //some code here
}

class Boo extends Foo {

}
+1

. , .

You can extend any class until it is final.

Edit: what I wanted to say is that it is preferable to host Unimplemented methods in interfaces. Sorry for the poor wording. There may be unrealized methods in abstract classes, although in the end you will have a complex and rigid hierarchy. ,

0
source

All Articles