answersLogoWhite

0


Best Answer

* void - This is a return type - or, more correctly, specifies that a method has no return type.

* protected - This is an access modifier. It says that the only classes that can call this method are subclasses and classes in the same package.

* int - This is a value type (or return type).

* main - This is the name of the method.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which of these is an access modifier for a method - void protected int or main?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What does public mean in java?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


Explain the difference between public and protected access specifier?

A private variable is only accessible in the class where it was declaredA protected variable is accessible to sub classes and classes in the same package as where they were declared


What is public access specifier?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are: 1. Public 2. Protected 3. Default and 4. Private Private is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object. Java programming does not run by just a single piece of class that has the whole functionality. You have hundreds of classes that interact with one another, passing data between them and returning output to the user of the system. So it is very important for members of one class to access members of another. Here members may refer to variables, methods and even classes. So, this is where the access modifiers come into picture. The modifier associated with every member of the class determines what level of visibility that member has.


What is a default value?

A default value is the one that has been considered the most appropriate on severalsystems, methods, programs. Obviously it is the parameter which works better, otherwise it wouldn't be set as a standard value. To set something "by default" is the same as to choose a value, a configuration more convenient for that purpose.


What happens if the static modifier is removed from the signature of the main program in java?

Actually speaking nothing major happens. That method would become just another method in the class. You cannot use that as the method to begin the program execution in your class. Your class will not be a standalone java program and you cannot execute it like you did before using the public static void main() method.

Related questions

What does public mean in java?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


What is protected in Java?

Protected and Default Access Levels:The protected and default access control levels are almost identical, but with one critical difference. A default member may be accessed only if the class accessing the member belongs to the same package, whereas a protected member can be accessed (through inheritance) by a subclass even if the subclass is in a different package.Take a look at the following two classes:package certification;public class ClassOne {void testIt() { // No modifier means method has default accessSystem.out.println("ClassOne");}}In another source code file you have the following:package otherCertification;import certification.ClassOne;class ClassTwo {static public void main(String[] args) {ClassOne o = new ClassOne();o.testIt();}}As you can see, the testIt() method in the first file has default (think: package-level) access. Notice also that class OtherClass is in a different package from the AccessClass. When you compile the ClassTwo.java file you will get an error like below:No method matching testIt() found in classcertification.ClassOne.o.testIt();From the preceding results, you can see that AccessClass can't use the OtherClass method testIt() because testIt() has default access, and AccessClass is not in the same package as OtherClass. So AccessClass can't see it, the compiler complains.Default and protected behavior differs only when we talk about subclasses. If the protected keyword is used to define a member, any subclass of the class declaring the member can access it through inheritance. It doesn't matter if the superclass and subclass are in different packages, the protected superclass member is still visible to the subclass. This is in contrast to the default behavior, which doesn't allow a subclass to access a superclass member unless the subclass is in the same package as the superclass. (See the example above)Whereas default access doesn't extend any special consideration to subclasses, the protected modifier respects the parent-child relationship, even when the child class moves away (and joins a new package). So, when you think of default access, think of package restrictions. No exceptions at all. But when you think protected, think package + kids. A class with a protected member is marking that member as having package-level access for all classes, but with a special exception for subclasses outside the package.


Difference between public nd default access specifier?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are:1. Public2. Protected3. Default and4. PrivatePrivate is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object.Public Members:If a variable or method is declared public, it means that it can be accessed by anyone or any other class (irrespective of which package they are in). Of course, it is mandatory that the class inside which the public method is placed is visible in the first place for the method or variable to be visible. You can check out the code example in the previous paragraph for an example. The method from Dad class is visible and available for usage inside the son class.For a subclass, if a member of its superclass is declared public, the subclass inherits that member regardless of whether both classes are in the same package.Ex:package pack1;public class Parent {public String getName() {return "Parent";}}Package pack2;Import pack1.Parent;Public class Child extends Parent{Public String getParentsName() {return getName();}}If you see the example above, the child class is able to access the parent class's method getName() even without instantiating an object of the parent because it inherits the Parent class and all its method as part of the inheritance (extends) feature.Protected and Default Members:The protected and default access control levels are almost identical, but with one critical difference. A default member may be accessed only if the class accessing the member belongs to the same package, whereas a protected member can be accessed (through inheritance) by a subclass even if the subclass is in a different package.Take a look at the following two classes:package certification;public class ClassOne {void testIt() { // No modifier means method has default accessSystem.out.println("ClassOne");}}In another source code file you have the following:package otherCertification;import certification.ClassOne;class ClassTwo {static public void main(String[] args) {ClassOne o = new ClassOne();o.testIt();}}As you can see, the testIt() method in the first file has default (think: package-level) access. Notice also that class OtherClass is in a different package from the AccessClass. When you compile the ClassTwo.java file you will get an error like below:No method matching testIt() found in classcertification.ClassOne.o.testIt();From the preceding results, you can see that AccessClass can't use the OtherClass method testIt() because testIt() has default access, and AccessClass is not in the same package as OtherClass. So AccessClass can't see it, the compiler complains.Default and protected behavior differs only when we talk about subclasses. If the protected keyword is used to define a member, any subclass of the class declaring the member can access it through inheritance. It doesn't matter if the superclass and subclass are in different packages, the protected superclass member is still visible to the subclass. This is in contrast to the default behavior, which doesn't allow a subclass to access a superclass member unless the subclass is in the same package as the superclass. (See the example above)Whereas default access doesn't extend any special consideration to subclasses, the protected modifier respects the parent-child relationship, even when the child class moves away (and joins a new package). So, when you think of default access, think of package restrictions. No exceptions at all. But when you think protected, think package + kids. A class with a protected member is marking that member as having package-level access for all classes, but with a special exception for subclasses outside the package.


Explain the difference between public and protected access specifier?

A private variable is only accessible in the class where it was declaredA protected variable is accessible to sub classes and classes in the same package as where they were declared


How is a method define?

[Access Specifier] [Modifier] return-type function-name(Parameter list) { body of the function } Example: public override void printHelloWorld(int count) { for(int i = 0; i < count; i++) { System.out.println("Hello world!"); } }


Why static is used in main method?

It is declared static because the JVM would need to execute the main method and if it is not static the JVM would need an object of the class to access the method. How can the JVM get an object of a class without invoking it. since it is static, the JVM can easily access it without this need to have an object of the class.


What is public access specifier?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are: 1. Public 2. Protected 3. Default and 4. Private Private is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object. Java programming does not run by just a single piece of class that has the whole functionality. You have hundreds of classes that interact with one another, passing data between them and returning output to the user of the system. So it is very important for members of one class to access members of another. Here members may refer to variables, methods and even classes. So, this is where the access modifiers come into picture. The modifier associated with every member of the class determines what level of visibility that member has.


What is a default value?

A default value is the one that has been considered the most appropriate on severalsystems, methods, programs. Obviously it is the parameter which works better, otherwise it wouldn't be set as a standard value. To set something "by default" is the same as to choose a value, a configuration more convenient for that purpose.


Determine the defense area and the prevention method and equipment of each defense?

After the location and area that are vulnerable to intrusion are determined, we need to determine the prevention method and equipment for each defense area. It is better to have all areas protected. But if the environment situation and community security is good, you can only have the main entrance areas protected.


What part of speech is can convince?

"Can convince" is a verbal phrase.Convince is the main verb and can is the modifier.


What happens if the static modifier is removed from the signature of the main program in java?

Actually speaking nothing major happens. That method would become just another method in the class. You cannot use that as the method to begin the program execution in your class. Your class will not be a standalone java program and you cannot execute it like you did before using the public static void main() method.


Is it possible to call static methods with out creating object?

Yes, we can access all methods which declare with static means then we can access.. ex: class s{ static method() { System.out.println("Welcome"); } } class fun{ public static void main(String args[]) { method(); } }