263). Which of these is the method which is executed first before execution of any other thing takes place in a program?
[A]main method
[B]finalize method
[C]static method
[D]private method
Show Answer
Correct Answer: static method
Notes:
Answer: c
Explanation: If a static method is present in the program then it will be executed first, then main will be executed.
264). What is the process of defining more than one method in a class differentiated by parameters?
[A]Function overriding
[B]Function overloading
[C]Function doubling
[D]None of the mentioned
Show Answer
Correct Answer: Function overloading
Notes:
Answer: b
Explanation: Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number. Example – int volume(int length, int width) & int volume(int length , int width , int height) can be used to calculate volume.
265). Which of these can be used to differentiate two or more methods having the same name?
[A]Parameters data type
[B]Number of parameters
[C]Return type of method
[D]All of the mentioned
Show Answer
Correct Answer: All of the mentioned
Notes:
Answer: d
Explanation: None.
266). Which of these data type can be used for a method having a return statement in it?
[A]void
[B]int
[C]float
[D]both int and float
Show Answer
Correct Answer: both int and float
Notes:
Answer: d
Explanation: None.
267). Which of these statement is incorrect?
[A]Two or more methods with same name can be differentiated on the basis of their parameters data type
[B] Two or more method having same name can be differentiated on basis of number of parameters
[C] Any already defined method in java library can be defined again in the program with different data type of parameters
[D] If a method is returning a value the calling statement must have a variable to store that value
Show Answer
Correct Answer: If a method is returning a value the calling statement must have a variable to store that value
Notes:
Answer: d
Explanation: Even if a method is returning a value, it is not necessary to store that value.
268). What will be the output of the following Java program?
class box
{
int width;
int height;
int length;
int volume;
void volume(int height, int length, int width)
{
volume = width * height * length;
}
}
class Prameterized_method{
public static void main(String args[])
{
box obj = new box();
obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(3, 2, 1);
System.out.println(obj.volume);
}
}
Show Answer
Correct Answer: 6
Notes:
Answer: c
Explanation: None
output:$ Prameterized_method.java
$ Prameterized_method
6
269). What will be the output of the following Java program?
class equality
{
int x;
int y;
boolean isequal()
{
return(x == y);
}
}
class Output
{
public static void main(String args[])
{
equality obj = new equality();
obj.x = 5;
obj.y = 5;
System.out.println(obj.isequal);
}
}
[A]false
[B]true
[C]0
[D]1
Show Answer
Correct Answer: true
Notes:
Answer: b
Explanation: None
output:
$ javac Output.java
$ java Output
true
270). What will be the output of the following Java program?
class box
{
int width;
int height;
int length;
int volume;
void volume()
{
volume = width * height * length;
}
void volume(int x)
{
volume = x;
}
}
class Output
{
public static void main(String args[])
{
box obj = new box();
obj.height = 1;
obj.length = 5;
obj.width = 5;
obj.volume(5);
System.out.println(obj.volume);
}
}
Show Answer
Correct Answer: 5
Notes:
Answer: b
Explanation: None.
output:
$ javac Output.java
$ java Output
5
271). What will be the output of the following Java program?
class Output
{
static void main(String args[])
{
int x , y = 1;
x = 10;
if(x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
[A]1
[B]2
[C]Runtime Error
[D]Compilation Error
Show Answer
Correct Answer: Compilation Error
Notes:
Answer: d
Explanation: main() method must be made public. Without main() being public java run time system will not be able to access main() and will not be able to execute the code.
output:
$ javac Output.java
Error: Main method not found in class Output, please define the main method as:
public static void main(String[] args)
272). What will be the output of the following Java program?
class area
{
int width;
int length;
int height;
area()
{
width = 5;
length = 6;
height = 1;
}
void volume()
{
volume = width * height * length;
}
}
class cons_method
{
public static void main(String args[])
{
area obj = new area();
obj.volume();
System.out.println(obj.volume);
}
}
Show Answer
Correct Answer: 30
Notes:
Answer: d
Explanation: None.
output:
$ javac cons_method.java
$ java cons_method
30