Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

private instance variable inside an abstract class

 
Fran Kindred
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I expected the compiler to complain because I dont see the point of allowing private class variables. I know private methods are not allowed in an abstract class but why is the compiler not complaining is there a use for this case.

 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An abstract class can have non-abstract methods that use the private variable.

By the way, an abstract class can have private methods. No class can have a private abstract method, as there would be no way to implement that method in a subclass.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic