| |

VerySource

 Forgot password?
 Register
Search
View: 643|Reply: 6

Declaring a non-static method of a package access class as public does not make sense! ?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-1 19:20:01
| Show all posts |Read mode
Because this class is not visible outside the package, it cannot call any of its non-static methods (can static methods be used?). Isn't it? thanks, thanks!
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-3-15 12:15:01
| Show all posts
Any public class is visible inside and outside the package, only non-public classes are not visible outside the package.
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-3-15 13:00:02
| Show all posts
The key is that non-static methods can only be called from objects, not from classes.
Only static methods can be called directly on the class name without generating an object.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-16 13:15:01
| Show all posts
Ok. It's talking about the package access class (non-public class). Is the above statement correct?
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-3-16 19:00:01
| Show all posts
Non-public classes, classes can't be seen, how can they access their non-static methods?
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-3-16 20:00:02
| Show all posts
Oh, it's static.
After all, static and non-static are not directly accessible, huh, huh.
Reply

Use magic Report

0

Threads

73

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 Invalid IP Address

Post time: 2020-3-17 09:15:01
| Show all posts
Package access classes whose "method declaration is publicly meaningless" are not more meaningful than non-public methods.
But there are special cases, such as a package access permission class, inheriting another public class, or implementing a public interface, then those overloaded or implemented methods must not be less than the parent class's limit, if The parent class is public, and it can only be public.
And these methods can indeed be accessed indirectly from the parent class reference.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list