Computer Applications
Which of the following is a valid initialisation statement?
- int x = "GOOD";
- int y = 45.0/2;
- int z = (int)'x';
- int m = false ;
Values & Data Types Java
1 Like
Answer
int z = (int)'x';
Reason
int x = "GOOD";—"GOOD"is a String literal, not an integer. We cannot assign aStringto a variable of typeint.int y = 45.0/2;—45.0is a double literal, so the result of the division is adouble. Assigning adoublevalue to anintwithout explicit typecasting causes a type mismatch error.int z = (int)'x';— This is a valid initialization because the character'x'is explicitly typecast to an integer, storing its Unicode value in the variablez.int m = false ;—falseis a boolean literal. We cannot assign abooleanvalue to a variable of typeint.
Answered By
1 Like
Related Questions
Assertion: Property by virtue of which one class acquires the properties of another class is termed as Inheritance.
Reason: Inheritance promotes reusability.
- Assertion is true, Reason is false.
- Assertion is true, Reason is true.
- Assertion is false, Reason is false.
- Assertion is false, Reason is true.
Which of the following is NOT true for polymorphism?
- All methods have the same name.
- Methods are invoked based on the arguments.
- Methods should have the same number and the same type of arguments.
- It is a principle of OOPs.
Which of the following is a valid statement to print the following sentence:
Raj said "Good morning"
- System.out.println("Raj said "Good morning");
- System.out.println("Raj said \\Good morning\\);
- System.out.println("Raj said \"Good morning\" ");
- System.out.println("Raj said Good morning");
Which data structure is represented in the below picture?

(i) A two-dimensional array with 2 rows and seven columns.
(ii) A one-dimensional array with 14 elements.- Both (i) and (ii)
- Only (i)
- Only (ii)
- None of the (i) and (ii)