Java Programming Questions and Answers Set 13

Java Programming OOPs

Questions 121 to 130



121.
Which of the following can Java run from a Web browser exclusively?
(a)
Applications
(b)
Applets
(c)
Servlets
(d)
Micro Edition programs
(e)
All of the above.
122.
Which of the following language is Architecture-Neutral?
(a)
Java
(b)
C++
(c)
C
(d)
Ada
(e)
Pascal.
123.
How the main method header is written in Java?
(a)
public static void main(string[] args)
(b)
public static void Main(String[] args)
(c)
public static void main(String[] args)
(d)
public static main(String[] args)
(e)
public void main(String[] args).
124.
What is the extension name of a Java source code file?
(a)
.java
(b)
.obj
(c)
.class
(d)
.exe
(e)
.javac.
125.
Which of the following is not the reserved words in java?
(a)
Public
(b)
Static
(c)
Void
(d)
Class
(e)
Num.
126.
Suppose
static void nPrint(String message, int n) {
   while (n > 0) {
     System.out.print(message);
     n--;
   }
}
What is the printout of the call Print('a', 4)?
(a)
aaaaa
(b)
aaaa
(c)
aaa
(d)
aa
(e)
invalid call.
127.
Analyze the following code.
public class Test {
public static void main(String[] args) {
  System.out.println(max(1, 2));
}
 public static double max(int num1, double num2) {
   System.out.println("max(int, double) is invoked");
 if (num1 > num2)
   return num1;
 else
   return num2;
 }
      public static double max(double num1, int num2) {
System.out.println("max(double, int) is invoked");
if (num1 > num2)
  return num1;
 else
   return num2;
 }
}
(a)
The program cannot compile because you cannot have the print statement in a non-void method
(b)
The program cannot compile because the compiler cannot determine which max method should be invoked
(c)
The program runs and prints 2 followed by "max(int, double)" is invoked
(d)
The program runs and prints 2 followed by "max(double, int)" is invoked
(e)
The program runs and prints "max(int, double) is invoked" followed by 2.
128.
Analyze the following code.
public class Test {
public static void main(String[] args) {
  System.out.println(m(2));
}
public static int m(int num) {
  return num;
}
public static void m(int num) {
  System.out.println(num);
}
}
(a)
The program has a syntax error because the two methods m have the same signature
(b)
The program has a syntax error because the second m method is defined, but not invoked in the main method
(c)
The program runs and prints 2 once
(d)
The program runs and prints 2 twice
(e)
The program runs and prints 2 thrice.
129.
What is Math.rint(3.5)?
(a)
3.0
(b)
3
(c)
4
(d)
4.0
(e)
5.0.
130.
Analyze the following code:
public class Test {
public static void main(String[] args) {
  int[] x = new int[5];
  int i;
  for (i = 0; i < x.length; i++)
    x[i] = i;
  System.out.println(x[i]);
}
}
(a)
The program displays 0 1 2 3 4
(b)
The program displays 4
(c)
The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException
(d)
The program has syntax error because i is not defined in the last statement in the main method
(e)
The program displays 1 2 3 4 5.

Answers


121.
Answer : (b)
Reason  :       Applets run from a web browser.
122.
Answer : (a)
Reason  :       Java is architecture neutral.
123.
Answer : (c)
Reason  :       public static void main(String[] args) the  main method header is written in Java
124.
Answer : (a)
Reason  :       the extension name of a Java source code file .Java
125.
Answer : (e)
Reason  :       All are the reserved words of java.
126.
Answer : (e)
Reason  :       I nvalid call because char 'a' cannot be passed to string message
127.
Answer : (b)
Reason  :       This is known as ambiguous method invocation
128.
Answer : (a)
Reason  :       You cannot override the methods based on the type returned.
129.
Answer : (d)
Reason  :       rint returns the nearest even integer as a double since 3.5 is equally close to 3.0 and 4.0.
130.
Answer : (c)
Reason  :       After the for loop i is 6. x [5] is out of bounds.

<< Prev   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22  

 23   24   25   26   27   28   29   30  Next >>


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment