Java Programming Questions and Answers Set 19

Java Programming OOPs

Questions 181 to 190



181.
What is the printout of the following code?
double x = 5.5;
int y = (int)x;
System.out.println("x is " + x + " and y is " + y);
(a)
x is 5.0 and y is 6.0
(b)
x is 6.0 and y is 6.0
(c)
x is 6 and y is 6
(d)
x is 5.5 and y is 5.0
(e)
x is 5.5 and y is 6.5.
182.
Which of the following is the correct expression of character 4?
(a)
4
(b)
“4”
(c)
‘\0004’
(d)
‘4’
(e)
‘\4’.
183.
How many bytes a Java character uses for storing?
(a)
One byte
(b)
Two bytes
(c)
Three bytes
(d)
Four bytes
(e)
Five bytes.
184.
Which of the following assignment statement(s) is/are correct?
I.     char c = 'd';
II.     char c = 100;
III.    char c = "d";
IV.   char c = "100";
(a)
Only (I) above
(b)
Only (II) above
(c)
Both (I) and (II) above
(d)
Both (II) and (III) above
(e)
Both (III) and (IV) above.
185.
What does the expression (int)(76.0252175 * 100) / 100 evaluate to?
(a)
76.02
(b)
76
(c)
76.0252175
(d)
76.03
(e)
76.0352715.
186.
Which of the follows JDK command is correct to run a Java application in ByteCode.class?
(a)
java ByteCode
(b)
java ByteCode.class
(c)
javac ByteCode.java
(d)
javac ByteCode
(e)
JAVAC ByteCode.
187.
Suppose you define a Java class as follows:
public class Test {
}
In order to compile this program, the source code should be stored in a file named
(a)
Test. class
(b)
Test.doc
(c)
Test.txt
(d)
Test. java
(e)
Any name with extension .java.
188.
Which of the following statement is not true?
(a)
A default no-arg constructor is provided automatically if no constructors are explicitly declared in the class
(b)
At least one constructor must always be defined explicitly
(c)
Constructors do not have a return type, not even void
(d)
Constructors must have the same name as the class itself
(e)
Constructors are invoked using the new operator when an object is created.
189.
What is wrong in the following code?
class TempClass {
   int i;
   public void TempClass(int j) {
     int i = j;
   }
}

public class C {
   public static void main(String[] args) {
     TempClass temp = new TempClass(2);
   }
}
(a)
The program has a compilation error because TempClass does not have a default constructor
(b)
The program has a compilation error because TempClass does not have a constructor with an int argument
(c)
The program compiles fine, but it does not run because class C is not public
(d)
The program compiles and runs fine
(e)
All of the above.
190.
To declare a constant MAX_LENGTH as a member of the class, you write
(a)
Final static MAX_LENGTH = 99.98;
(b)
Final static float MAX_LENGTH = 99.98;
(c)
Static double MAX_LENGTH = 99.98;
(d)
Final double MAX_LENGTH = 99.98;
(e)
Final static double MAX_LENGTH = 99.98;.

Answers

181.
Answer : (d)
Reason:  The value is x is not changed after the casting.
182.
Answer : (d)
Reason:  You have to write '4'.
183.
Answer : (b)
Reason:  Java characters use Unicode encoding.
184.
Answer : (c)
Reason:  Choice (B) is also correct, because an int value can be implicitly cast into a char variable. The Unicode of the character is the int value. In this case, the character is d
185.
Answer : (b)
Reason:  Your answer D is incorrect
In order to obtain 76.02, you have divide 100.0.
186.
Answer : (a)
Reason:  A is the right choice.
187.
Answer : (d)
Reason:  Test.java is the name of the source code of the file.
188.
Answer : (b)
Reason:  There is no certain rule that at least one constructor must always be defined explicitly.
189.
Answer : (b)
Reason:  The program would be fine if the void keyword is removed from public void TempClass(int j).
190.
Answer : (e)
Reason:  E is the right way to represent.


<< 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