Which will declare a method that is available to all member of same package and can be refferenced without instance of class? public/protected/private/abstract/no access specifier needed Can any one explain this who has good understanding of access modfiers. Also kly explain this question....
Let's consider like this: Member of a package are top level classes and interfaces only. (non-static inner classes are not members of a package) Now before a method is accessible, its class must be accessible. A class, which is declared with any one of the access modifiers- public, protected, or default access, is accessible throughout the package in which this class is declared. Therefore a method, which is declared within this class using any one of the access modifiers- public, protected, or default access is accessible through out this package. [The modifier private is ruled out] But to be referenced without an instance of a class, the method must also have a static modifier(FYI: static is not an access modifier but is an class-member modifier). I see "static" modifier is missing in your question. Without this modifier, I think that you cannot call a method from outside this class without an instance of this class. This is what I think. Please let me know if I overlooked something.
Hi Venky, Are you sure that the question is correct? If it correct, then the answer should be abstract. This is because, any abstract method can only be declared in a class which is declared abstract explicitly. Now, that we have an abstract class in a package and we want to call the method, we will need to inherit the class. When we inherit the class, we don't need to make an instance of the class. If we want to call a abstract method declared, we will first have to define a body for the method. Then we can call the method in the class. An abstract class can also contain methods which already have a body definition. IN this case, you can also call those methods by their simple name, as they have been inherited. Hope it helps. Niraj
posted 18 years ago
I agree with Neeraj's reply. It should be abstract only. Thanks neeraj, for explaining it neatly. Rgds Venky