java - Class access modifier -
I have the following two classes
package one; Public class student {/ some code} package two; Public Class Test {Public Stable Zero Main (String AZ []) {Student S = New Student (); // some codes}} Even if the "student" category has a public access modifier, whenever I try to create an object for the student class, in the test class, which The other is the package, the mistake is saying that either I must import the student class or make a new class.
I thought that if a class has been declared public then it can be reached from any place. But why do eclipse call it an error?
You do not have a import statement, so the compiler does not know that Student reference one. The student / <> is the code. You can either use: import one. student; or
import one. *; ... or when you create an object, fully qualify the name:
one.Student s = new.Student (); This is not the point of access - this is not a compiler who does not know how to solve identifier student in the name of fully qualified class.
Comments
Post a Comment