When every class in Java derives from java.lang.Object then what is the purpose of having protected methods in the Object class? They will always have the same visibility as public methods.Is there any reason why the following two methods are protected in the OpenJDK implementation?
protected native Object clone() throws CloneNotSupportedException;
protected void finalize() throws Throwable { }
Edit: The comment stating new Object.finalize() is the best answer I could have anticipated! ..Thanks
For those who are differentiating accessibility of protected and public
package pkg1;
public class Parent{
protected void fun(){}
}
package pkg2;
public class child extends pkg1.Parent{
void fun2()
{ child ch=new child();
ch.fun(); // Accesses protected method (For this class protected /public is irrelevant in terms of accessibility
Parent p=new Parent();
//p.fun(); //can't do this
}
}