Private concrete methods in Abstract class

Post Reply
yrelhan
Posts: 5
Joined: Wed Jun 07, 2017 3:13 am
Contact:

Private concrete methods in Abstract class

Post by yrelhan » Wed Jun 14, 2017 2:29 pm

The official Java docs says "However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods"

How to call the private methods in an abstract class?

Also can an abstract class have private instance variables?

admin
Site Admin
Posts: 7449
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Private concrete methods in Abstract class

Post by admin » Thu Jun 15, 2017 2:28 am

Here is an example:

Code: Select all

abstract class Animal{
  private int id = 0; //private instance variable
  private void log(){  
     System.out.println("in private do x");
  }
  public void doX(){
    log(); //call private method
  }
}
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests