Why are there public, static, void, & main keyword in main method of every Java Program | Top 20 Java Interview Questions | Part 6
Top 20 Java Interview Questions | Core Java Interview Question Series | Part 6
This is the sixth part of the Core Java interview questions Series in which we will dicuss the next 20 Core java interview questions. For the previous 100 Java interview questions Click Here: Core Java interview questions Part 1  Core Java interview questions Part 2  Core Java Interview questions Part 3 Core Java Interview question part 4 Core Java interview question Part 5  so let us start.Â
Q.102). What is access modifier?
Ans. It is used to change the accessibility of Java components. We have four access modifiers 1). Private 2). Public 3). Default 4). Protected
Q.103). What is private access modifier?
Ans. It is a class modifier, it is responsible for variables, methods, and constructors. If the member of a class is private then it is accessible only within the class, outside the class is not possible.
Q.104). What is the default access modifier?
Ans. The accessibility of the default modifier is only within the package. It cannot be accessed externally from the package. If you do not declare any access modifier then it is considered as default access modifier
Q.105). What is protected?
Ans. The access level of a protected modifier is limited to within the package and also extends to subclasses outside the package. If you do not have to make the class child, then It cannot be accessed externally from the package.
Q.106) What is public?
Ans. The access level of public modifiers is everywhere. It can be accessed from within the class, outside the class, within the package as well as outside the package.
Q.107) What is the return type?
Ans. The type of data returned by the method after execution is completed to the caller or calling method. The return type is connected with the return statement because the method is returning the data to the caller with the help of return statement.Note: Software testing jobs service
Q.108) What is the return statement?
Ans. It is used to return the value to the caller method. It is done with the help of the return keyword.Q.109) What is the return keyword?
Ans. Return is a keyword. It is a control transfer statement when the return statement is executed, the execution of the method is terminated and control is transferred to the calling method.Syntax: return [Data/variable/expression/statement]
Q.110) What is the void return type?
Ans. It is a keyword and datatype which is used as a return type of a method. It is a datatype because we cannot create a variable by using this. When the method does not promising to return anything to the caller. We are making the method return type void, when the method is having return type as void.Â
We can go with the return statement neither zero or null. because zero is primitive type data and null is non-primitive type data. When the method has having return type as void, it is not compulsory to mention the return statement inside the method.
Q.111) What are the types of methods?
Ans. Based on formal arguments, it is of two typesÂ
1). No arguments methodÂ
2). Parameterized method
Q.112) What is no argument method?
Ans. The method which does not have any formal arguments is known as the no argument method.
Q.113) What is the parameterized method?
Ans. The method that has arguments is known as a parameterized method. Parameterized methods are used to accept the data.
Q.114) What is the formal argument?
Ans. A variable declared in a method declaration is known as a formal argument.
Q.115) What are actual arguments?
Ans. The values passed in the method call statement are known as actual arguments.
Q.116) What isthe method call statment?
Ans. The statement which is used to call a method is known as the method call statement.
Q.117) What are the rules for calling the parameterized method?
Ans.Â
- The number of actual arguments should be the same as the number of formal arguments.
- The type of corresponding actual argument should be the same as the type of formal argument if not compiler tries to convert implicit conversion if it is not possible then we will get a compile time error.
- The sequence of the actual argument should be the same as the sequence of the formal argument.
Q.118) What is the main method?
Ans. In Java, the main method is the entry gate of any program. From the main method, start the execution of the program.Â
Public static void main(string[] args)
{
}
Q.119) Why public keyword is there in the main method?
Ans. The main method is public so that JVM can access the main method from outside the class
Q.120) Why static keyword is there in the main method?
Ans. Main method is static so that JVM can call the main method directly without creating the object.
Q.121) Why void keyword is there in the main method?
Ans. Main method is void because after execution is done by the main method. It is not going to return any value to the JVM.
Q.122) Why the main keyword is there in the main method?
Ans. This is the identifier of the method which is known by the JVM to start the execution. JVM has to call this method.
Q.123) What is string[] args
Ans. It is string[] args as an argument because we can call the main method through JVM by passing the multiple data which can be any type with the help of command prompt.
Q.124) What is a command line argument?
Ans. The data or argument we pass through the command prompt through the JVM after the class name is known as the command line argument.
Ex. Java className hello Rajat
Hello rajat is the command line argument
Post a Comment