#Is this true?

1 messages · Page 1 of 1 (latest)

simple sapphire
#

Even if a class is public, by default, variables inside can only be accessed by classes within the same package.  Variables themselves need to be made public as well in order to import them from outside the package.

viral plumeBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

No, this statement is not true. In Java, if a class is declared as public, it means that it can be accessed by any other class, regardless of whether they are in the same package or not. However, the visibility of variables within a class depends on their access modifiers.

By default, if no access modifier is specified for a variable (also known as package-private or default access), it can be accessed by other classes within the same package. If you want to make a variable accessible to classes outside the package, you need to explicitly declare it as public.

To import a class in Java, you don't need to make its variables public. Importing a class simply allows you to use its methods and variables without specifying the fully qualified name each time. The accessibility of variables within the class itself is determined by their access modifiers.

rapid plover
#

thats why u have access modifiers and getters / setters

fallen widget
#

if u omit the access modifier, it implicitly means package-visible

#

not only for fields, also for methods or classes

simple sapphire
remote quest
#

yeah

simple sapphire
#

Ok thanks!

#

How do i tag this problem as solved or does this server have such a feature?

remote quest
#

let me do it

viral plumeBOT
#

Closed the thread.

simple sapphire
#

Thanks

remote quest
#

np, you opened it again though lmao

#

but all good

simple sapphire
#

oh ahahs

remote quest
#

2min cooldown