MCQs
Total Questions : 31
| Page 2 of 4 pages
Answer: Option C. -> 0.0
Answer: Option A. -> Method 1
Answer: Option C. -> Compile time error
Answer: Option C. -> does not compile
Answer: Option B. -> A class object in which it is defined.
Answer: Option D. -> Before garbage collection.
Answer: Option C. -> It can be executed without creating any instance of the class.
Question 18. Which of the following statements regarding static methods are correct?
1. Static methods are difficult to maintain, because you can not change their implementation.
2. Static methods can be called using an object reference to an object of the class in which this method is defined.
3. Static methods are always public, because they are defined at class-level.
4. Static methods do not have direct access to non-static methods which are defined inside the same class.
1. Static methods are difficult to maintain, because you can not change their implementation.
2. Static methods can be called using an object reference to an object of the class in which this method is defined.
3. Static methods are always public, because they are defined at class-level.
4. Static methods do not have direct access to non-static methods which are defined inside the same class.
Answer: Option B. -> 2 and 4
Question 19. Given the following piece of code:
class Person{
public int number;
}
public class Test{
public void doIt(int i , Person p){
i = 5;
p.number = 8;
}
public static void main(String args[]){
int x = 0;
Person p = new Person();
new Test().doIt(x, p);
System.out.println(x + " " + p.number);
}
}
What is the result?
class Person{
public int number;
}
public class Test{
public void doIt(int i , Person p){
i = 5;
p.number = 8;
}
public static void main(String args[]){
int x = 0;
Person p = new Person();
new Test().doIt(x, p);
System.out.println(x + " " + p.number);
}
}
What is the result?
Answer: Option A. -> 0 8
Answer: Option D. -> public Test( )