ExamVeda
Login
Home
31
Java is a ........... language.
Discuss
Answer & Solution
Answer: Option B
Solution:
The correct answer is Option B: strongly typed

In Java, it is recognized as a strongly typed language. A strongly typed language enforces strict type checking, meaning that the data type of a variable is checked at compile time and any type mismatches are not allowed without explicit typecasting.

Here's an explanation of the other options:

- Option A: weakly typed does not apply to Java. Weakly typed languages are those that allow for automatic type conversions and do not enforce strict type checking.

- Option C: moderate typed is not a standard term in programming language classification. Java is typically classified as strongly typed.

- Option D: None of these is not the correct choice as Java is indeed classified as a strongly typed language.
32
How many primitive data types are there in Java?
Discuss
Answer & Solution
Answer: Option C
Solution:
Primitive types are the most basic data types available within the Java language. There are 8: boolean , byte , char , short , int , long , float and double .
33
In Java byte, short, int and long all of these are
Discuss
Answer & Solution
Answer: Option A
Solution:
In Java, byte, short, int, and long are all signed integer data types.

Here's the breakdown:

Option A: signed - This option is correct. byte, short, int, and long are all signed integer data types in Java, which means they can represent both positive and negative whole numbers.

Option B: unsigned - This option is not correct. Java does not have built-in unsigned integer data types. Unlike some other programming languages, all integer data types in Java are signed by default.

Option C: Both of the above - This option is not correct because only Option A is true. Java integer data types are signed, not unsigned.

Option D: None of these - This option is not correct because Option A is the correct answer. Java's byte, short, int, and long are all signed integer data types.

So, in Java, byte, short, int, and long are all signed integer data types.
34
Size of int in Java is
Discuss
Answer & Solution
Answer: Option B
Solution:
The size of an int in Java is 32 bits.

Here's the breakdown:

Option A: 16 bit - This is not correct. The int data type in Java is 32 bits in size, not 16 bits.

Option B: 32 bit - This is the correct size of an int in Java. An int occupies 32 bits of memory in Java, allowing it to represent a wide range of whole numbers.

Option C: 64 bit - This size is not correct for an int in Java. A 64-bit data type is larger and typically used for long integers.

Option D: Depends on execution environment - The size of an int in Java is standardized and is always 32 bits regardless of the execution environment. It is not dependent on the platform or execution environment.

So, the correct size of an int in Java is 32 bits.
35
The smallest integer type is ......... and its size is ......... bits.
Discuss
Answer & Solution
Answer: Option B
Solution:
The smallest integer type in Java is byte, and its size is 8 bits.

Here's the breakdown:

Option A: short, 8 - This option is not correct. While short is a small integer type, its size is 16 bits (2 bytes), not 8 bits.

Option B: byte, 8 - This option is correct. The byte data type is the smallest integer type in Java, and it has a size of 8 bits (1 byte).

Option C: short, 16 - This option is not correct. While short has a size of 16 bits, it is larger than the byte data type.

Option D: byte, 16 - This option is not correct. The size mentioned here, 16 bits, is incorrect for the byte data type. The correct size of byte is 8 bits.

So, the correct answer is that the smallest integer type in Java is byte, and its size is 8 bits.
36
Size of float and double in Java is
Discuss
Answer & Solution
Answer: Option A
Solution:
The size of float in Java is 32 bits, and the size of double in Java is 64 bits.
37
Determine output:
class A{
        public static void main(String args[]){
	        int x;
 	        x = 10;
	        if(x == 10){
		        int y = 20;
		        System.out.print("x and y: "+ x + " " + y);
		        y = x*2;
	        }
	        y = 100;
	        System.out.print("x and y: " + x + " " + y);
        }
}
Discuss
Answer & Solution
Answer: Option D
Solution:
The code defines a class A with a main method.
Inside the main method:
- An integer variable x is declared and assigned the value 10.
- There's an if statement that checks if x is equal to 10. This condition is true.
- Inside the if block:
- Another integer variable y is declared and assigned the value 20.
- The program prints "x and y: 10 20" using System.out.print.
- The value of y is updated to x * 2, which is 20.
- Outside the if block:
- The program attempts to update the value of y to 100. However, this line causes a compilation error because the variable y was declared inside the if block and is not accessible outside of it.
- The program also attempts to print "x and y: 10 100". This line also causes a compilation error because the variable y is not in scope at this point.

So, the correct answer is "Error" because the code contains compilation errors due to the variable y being declared within the if block and not being accessible outside of it. The program cannot find the symbol y outside of the if block, leading to compilation errors.
38
Automatic type conversion in Java takes place when
Discuss
Answer & Solution
Answer: Option C
Solution:
The correct answer is C: Two types are compatible and the size of the destination type is larger than the source type.

Automatic type conversion, also known as implicit type conversion or widening conversion, happens when Java automatically converts one data type to another.

This occurs when two conditions are met:

1. Compatibility: The two data types must be compatible. Java must know how to convert from the source type to the destination type.

2. Size: The destination type must be larger than the source type so that no data is lost.

Why other options are wrong:

Option A: If destination is shorter than source, data loss may occur. Java does NOT allow this automatically. It needs explicit casting.

Option B: If both types are equal in size, conversion is not needed because the source already fits.

Example:

int myInt = 10;
double myDouble = myInt; // Allowed, widening conversion

double myDouble2 = 10.5;
int myInt2 = (int) myDouble2; // Needs explicit cast because narrowing may lose data
39
Which of the following automatic type conversion will be possible?
Discuss
Answer & Solution
Answer: Option D
Solution:
Option A: short to int
Option B: byte to int
Option C: int to long

These conversions are possible because they involve widening conversions where the destination type can accommodate the values of the source type without loss of information.

So, the correct answer is: Option D: All of these
40
What is the output of the following program?
class A{
        public static void main(String args[]){
	        byte b;
   	        int i = 258;
	        double d = 325.59;

	        b = (byte) i;
	        System.out.print(b);

	        i = (int) d;
	        System.out.print(i);

                b = (byte) d;
                System.out.print(b);
        }
}
Discuss
Answer & Solution
Answer: Option C
Solution:

In the type cast
b = (byte) i;
The value of i i.e 258 is cast into a byte variable. Whenever a casting done where source value is greater than the range of the destination then the result is the remainder of the division of source by the range of the destination. In this case the result is the remainder of the division of 258 by 256(the range of a byte), which is 2.

In the second type cast
i = (int) d;
the fractional component of d is lost and hence gives the output 325.

In the third type cast