Tuesday, 15 May 2012

What is the default access level for methods in a public abstract class in Java? -


Generally the default access level of the methods is local package. But I think it is different for public abstract sections; it appears to be the default in those sections, is this right?

Update

@EJP

This was a bug in my code, it is possible to shade the package local method with a public method, which confused me I think that a public abstract can be similar to an interface where the methods are public, see examples:

a / ajava:

 < Code> package a; Public abstract class A {String A () {return "A"; }}   

test_a.java:

  class test_a {provides static class newa AA {public string A ()) "New A"; }} Public static zero main (string [] args) {new a = new neue (); Println (a.a ()); }}    

false , watch with a quick example :

  package package; A method with public intangible class abstractist {// default visibility summary (zero times); }   

A quick implementation:

  Expands public square Fu abstrfo {@Override void bar () {}}   

Now, in another package:

  public static zero main (string [] args throws exceptions {tables = something new) some .bar (); // compiler complains here   

The compiler complains about visibility. Therefore, the default visibility for methods is package protected , even if class public abstract

No comments:

Post a Comment