0% found this document useful (0 votes)
5 views5 pages

JavaAbstract

An abstract class in Java cannot be instantiated and is intended for inheritance, providing common behavior while requiring subclasses to implement certain abstract methods. It can contain both fully implemented and abstract methods, and if it has at least one abstract method, it must be declared abstract. Abstract methods cannot be private, static, or final, and static blocks in abstract classes execute when accessed or when a concrete subclass is created.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

JavaAbstract

An abstract class in Java cannot be instantiated and is intended for inheritance, providing common behavior while requiring subclasses to implement certain abstract methods. It can contain both fully implemented and abstract methods, and if it has at least one abstract method, it must be declared abstract. Abstract methods cannot be private, static, or final, and static blocks in abstract classes execute when accessed or when a concrete subclass is created.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

 abstract class in Java is a class that cannot be instantiated on its own.

 It is meant to be inherited by other classes to provide common behavior (methods,


variables) but force the subclasses to implement certain methods.
 It can have both:
o Fully implemented methods (normal methods)
o Abstract methods (methods without body — no implementation)
 a subclass must implement the abstract method:

 If a class has at least one abstract method, it must be declared abstract

 A class can be abstract even without abstract methods (for example, to prevent
instantiation).

 Abstract methods must be implemented in the subclass unless the subclass is also
abstract

 Cannot be private, static, or final


 Top level class cannot be private


Abstract Methods in an Abstract Class

 an inner class can be declared abstract in Java!


 Can a subclass access static methods from the abstract class? Yes, via the class name,
not an object

 If an abstract class has a static block, that block executes when the class is first
loaded.

 Even though the abstract class cannot be instantiated, its static blocks still execute
if:
o You access any static method or static variable of the abstract class.
o Or when a concrete subclass is created (and it indirectly loads the abstract
class).
 constructors in an abstract class are Package-private if you don't explicitly specify
an access modifier.

You might also like