class Test1 { public void method1() { System.out.println("super class method"); } }
class mura extends Test1 { public static void main(String args[]) { Test1 t2= new Test1(); t2.method1(); } void method1() { System.out.println("subclass method"); } }
Here i am getting compiler error saying
mura.java:17: method1() in mura cannot override method1() in Test1; attempting to assign weaker access privileges; was public void method1()
Plz explain this.
Bye Muralee ^
wise owen
Ranch Hand
Joined: Feb 02, 2006
Posts: 2023
posted
0
If the superclass method is public, the overriding method must be public. This is one of rules for overriding.
krish bajaj
Ranch Hand
Joined: Jun 19, 2006
Posts: 31
posted
0
hello murali listen it is the rule of overriding when u override a method u can not use those specifiers due to which weeker access done i mean if u will use private in superclass and then override the method with public then it will not give an error because access is stronger u can understant in the way of upcasting and downcasting
thanks Krish
Srilakshmi Vara
Ranch Hand
Joined: Jul 21, 2004
Posts: 169
posted
0
Murali,
You cannot override a public with default. The Overriding sequence can be like this