aspose file tools
The moose likes Beginning Java and the fly likes Query on Overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query on Overriding " Watch "Query on Overriding " New topic

Query on Overriding

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
When a method is overrided there is a restriction that the method in the sub class cannot be more restrictive than the original.

public void print() {} cannot be overrided to
protected void print() {}

But what about the default access specifier i.e "void print() {}" ?

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97

Default is more restrictive then protected and less then private.

Jimmy Die
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
So the it's like this

private --> default ---> protected --> public
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I assume the arrow (-->) means "is more restrictive than". If so, then you are correct.

[ February 24, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
It is sorta covered in the JavaRanch Style Guide.
subject: Query on Overriding
It's not a secret anymore!