Different rules of abstract methods in an abstract class and interface

We cannot declare abstract methods in the interface as protected and by default (even if we do not mention that the access specification compiler (by default) accepts it as public)

but we can declare an abstract method in an abstract class as protected and default.

Why are there different rules for an abstract class and interface?

+3
source share
2 answers

we cannot declare abstract methods in the interface as protected and defaul

the purpose of the interface is simply to declare a contract. your client will execute it, and for this it must be public.

public static final , , , , , .

Update:

- , ... ...

public class BaseAbstractClass {
  private Connection getConnection(){
      //somecode 

  }

  public boolean save(){
      //get connection and do something 
      //return ;
  }

//your implementor is left to implement it , he  can use save method but can'ge see what it does i mean i doesn't have access to getConnection
  public abstract void saveEntity();

}
+2

. , - " ". .

+6

Source: https://habr.com/ru/post/1788444/


All Articles