- Which of the following is an incorrect way of initializing a variable in Java?
- Different line declaration and initialization
int a,b;
a=1;
b=2;
- Single line declaration and initialization (One at a each line)
int a = 1;
int b = 2; - Single line declaration and initialization (One line multiple variable)
int a=l,b=2; - Single line declaration and initialization (One line multiple variable)
int a, b = 1, 2;
- Different line declaration and initialization
- Which of the following is an invalid method overloading?
- static double add (int a, double b) {return a*b;}
static double add (double a, int b) {return a*b; } - static int add (int a, int b) {return a*b; }
static int add (int a, int b, int c) {return a*b*c; }
- static int add (int a, int b) {return a*b; }
static double add (int a, int b, double c) (return a*b*c;}
- static int add (int a,int b) {return a*b; }
static double add (int a, int b) {return a*b; }
- static double add (int a, double b) {return a*b;}
- Which of the following is TRUE regarding the string array provided as a parameter to
the main method in Java?
- It can be used to get command line arguments from the user.
- It is mandatory to name the string array as 'args'.
- Accessibility of the values provided as command line argument is restricted only to the main method.
- Only one command line argument input is allowed at a time.
- Which of the following can be used to take input from user during the execution of a
program?
- Using the string array provided as a parameter to the main method.
- getText() method can be used to get user input from the command line.
- Scanner class can be used by passing the predefined object System.in
- Once the execution starts, there is no way to provide user input
- Which of the following is/are TRUE about print and println methods?
- print() prints in a single line only and multiple lines cannot be printed in any way.
- println() prints and then appends a line break
- println() prints in a single line only and multiple lines cannot be printed.
- print() prints and then appends a line break
- Which of the following is called when a method having the same name as that the name of
the class where it is defined?
- abstract
- this
- constructor
- final
- Which of the following is NOT true about a method in a class?
- A method can be defined recursively
- A method can be defined without any statement in it
- constructor is a special kind of method, which can be defined recursively
- A method can be defined with variable number of arguments passed into it
- Consider the following program.
Public class Questions {
public static void main (String args[]){
char a='2';
int b=8;
System.out.println (a+b);
}
}
What will be the output of the above program ?
3>- 10
- 58
- 82
- 106
- What will happen during the execution of the following code for the command line input?
Consider the following input on command line and select the options with the correct output
Public class Questions {
public static void main (String args[]){
System.out.println (args[5]);
}
}
3>
Input:
A I love my country
B 1 2 3 4 5 6
C I love my country india
D 12345
a.A ArrayIndexOutOfBounds Exception
b. B:6
C C: india
d D: 12345
- a
- b
- c
- d
- Which of the following is a Class in Java?
- int
- String
- short
- double
JAVA MCQs-2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment