All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Private concrete methods in Abstract class
PostPosted: Wed Jun 14, 2017 2:29 pm 
Offline

Joined: Wed Jun 07, 2017 3:13 am
Posts: 5
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?


Top
 Profile Send private message  
 
 Post subject: Re: Private concrete methods in Abstract class
PostPosted: Thu Jun 15, 2017 2:28 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6799
Here is an example:
Code:
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
  }
}


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL/ThatBigForum