?
Solved

overriding

Posted on 2007-10-19
2
Medium Priority
?
234 Views
Last Modified: 2010-03-30
hi,

in my superclass, i have a method called void protected print(),

this is strange but in my subclass, i am able to overide the protected method with either protected and public.

public class parent{

protected void print(){
System.out.println("In parent");
}
}

public class child extends parent{

public void print()
{
System.out.println("In child");
}

}

however, in parent i have public print and i try to override it protected, i get error: "print() in child cannot override print() in parent; attempting to assign weaker access privileges; was public
0
Comment
Question by:zizi21
2 Comments
 
LVL 23

Accepted Solution

by:
basicinstinct earned 2000 total points
ID: 20113625
if you override a method you are not permitted to make it less 'visible'... so if it is public in the superclass you can't make it protected (because protected is less visible than public).  If it is protected in the superclass you can go to public in the subclass because you are making it more visible.
0
 

Author Comment

by:zizi21
ID: 20113804
thank you very much.. Studying for exam and all this is helping a lot . God bless.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question