Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract methods and access modifier

 
Craig Oliver
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If abstract class declares abstract method what are rules regarding access modifier to implementation of method in concrete subclass? ie if abstract method declared as default (package) can subclass implementation be public (wider access)?

eg is following valid
public abstract class Test
{
abstract void m1();
}

public class SubTest extends Test
{
public void m1()
{
code
}
}
 
Darin Niard
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is valid. You can always assign broader access, but not weaker access.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic