简体   繁体   中英

public keyword for multiple methods/members

Is there any way I can mark more than 1 method as public without using the keyword multiple times?

at the moment, I have to do it for every method:

class foo
{
public void doSomething();
public void doAnotherthing();
public int counter;
}

But this get's pretty frustrating if you need to create more than 150 method declarations for a class, so, is there any other way?

No the public keyword is required if you want the equivalent of public access. This question should help: What is the difference between Public, Private, Protected, and Nothing?

Also the people who are saying that 150 methods is too many for a single class are right. A large part of the benefit of OOP is modularity. Each class should have a specific purpose and only contain methods specific to that purpose.

否,因为默认修饰符是该语言的private属性。

No, class with 150 method is called Elephant class. If you have 150 methods in class I recommend you to start reading object oriented programming.

By default if you write nothing with method then it is private for public you need to explicitly declare it public.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM