Java Object Model Elements: Abstract Class, Interface

The main idea of ​​the abstract class lies in the following thesis: sometimes not finished classes are required, but in a "raw" form. Such blanks cannot be directly used (create instances).

java abstract class




What is an abstract class in Java

. Java Calendar Java.util. , , , , , , . . , , : . .

, Java

, , , : , , . . , . , ( paint) -. : , , . . , .

abstract classes abstract methods java




But what about the paint method? After all, the parent class does not have a visual representation. If you declare the paint method in each class independently, you will need to analyze which component is being processed and then type cast. Therefore, the method must be declared abstract in the parent class: set the method title without a body. And the body of each derived class will describe its own. In Java, an abstract class can enclose abstract methods.





, . class abstract, – . . Java . , , . , . , abstract, final, . abstract, private, static, native. - , . .

:

  • abstract class AClass {
  • public abstract void method (int a);
  • }
  • class BClass extends AClass {
  • public void method (int a) {
  • //
  • }

. null.

Java –

java interfaces and abstract classes




Java , . . .





Java – , . public, , public, . abstract , , .

difference of abstract class from java interface




public, - interface. extends , . , , . , . : - . public final static - . public abstract - . Java.

  • public interface AI extends B, C, D {
  • //
  • }

, implements:

  • class AClass implements BI, CI, DI {}

, implements , . , .

. , , null. Object, , , , Object.

Java – , , .




All Articles