Posted on 2007-10-19
Last Modified: 2010-03-30

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
Question by:zizi21
    LVL 23

    Accepted Solution

    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.

    Author Comment

    thank you very much.. Studying for exam and all this is helping a lot . God bless.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    Which XML parser should I used for my requirement 11 48
    changePi Challenge 15 55
    pairstar challenge 2 26
    maven java path setting 5 31
    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…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    This video teaches viewers about errors in exception handling.

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now