0% found this document useful (0 votes)
23 views

Set-1 Java - Answers

Uploaded by

Clash Clan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Set-1 Java - Answers

Uploaded by

Clash Clan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Java_Answers

1. Which of the following is not a Java feature?

a. Dynamic
b. Architecture Neutral
c. Use of pointers
d. Object-oriented

Answer: Use of pointers


Explanation: The Java language does not support pointers.The major reasons are:

○ One of the major factors of not using pointers in Java is security concerns. Due
to pointers, most of the users consider C-language very confusing and complex.
This is the reason why Green Team (Java Team members) has not introduced
pointers in Java.

○ Java provides an effective layer of abstraction to the developers by not using


pointers in Java.

2. Which of these following components are used in Java programs for


compilation, debugging and execution?

a. JDK
b. JVM
c. JRE
d. JIT

Answer: JDK
Explanation: Get the concepts clear at: https://www.ibm.com/blog/jvm-vs-jre-vs-jdk/

3. Which of these literals can be contained in a float data type variable?

a. -3.4e+050
b. +1.7e+3,08
c. -3.4e+038
d. -1.7e+308

Answer: -3.4e+038
Topic: Primitive DataType
Explanation: Get the concepts clear at:
https://cs.fit.edu/~ryan/java/language/java-data.html

4. What is the numerical range of a char data type in Java?


a. 0 to 256
b. -128 to 127
c. 0 to 65535
d. 0 to 32767

Answer: 0 to 65535

Explanation: Char occupies 16-bit in memory, so it supports 216 i:e from 0 to 65535.
Topic: Primitive DataType
Get the concepts clear at: https://cs.fit.edu/~ryan/java/language/java-data.html

5. What is BigDecimal.ONE?

a. It is custom defined statement


b. It is a wrong statement
c. It is a static variable that has a value of 1 on a scale of 0.
d. It is a static variable that has a value of 1 on a scale of 10.

Answer: It is a static variable that has a value of 1 on a scale of 0.

6. When an expression consists of int, double, long, float, then the entire expression will
get promoted into a data type that is ?

a. Float
b. Double
c. Int
d. long

Answer: Double
Topic: Type casting
Explanation: Get the concepts clear at: Type-conversion-and-casting

7. Which of the following operators can act on a boolean variable?


A. &&
B. ==
C. ?:
D. +=

a. C&B
b. A&D
c. A,B&D
d. A,B&C

Answer: A,B&C
Topic: Operators
Explanation: Get the concepts clear at: https://data-flair.training/blogs/java-operators/

8. What is the use of final keyword in java?

a. When a class is made final, a subclass of it cannot be created


b. When a method is final, it cannot be overridden
c. When a variable is final, it can be assigned value only once
d. All of the above

Answer: All of the above


Explanation: Get the concepts clear at: https://www.javatpoint.com/final-keyword

9. What is the entry point of a program in Java?

A. main() method
B. The first line of code
C. Last line of code
D. main class

Answer: main() method

Explanation: Generally, the main() method is treated as the point where the flow of
code starts.

10. Array in java is ___.

A. Collection of similar elements


B. Collection of elements of different types
C. The data type of consisting of characters
D. None of these

Answer: Collection of similar elements

Explanation: Array is a collection of similar elements.

Get the concepts clear at: https://www.javatpoint.com/array-in-java

11. Which of these is the correct method to create an array in java?

A. int[] arr = {1, 3, 5};


B. int[] arr;
C. arr = new int[] {3, 1, 8};
D. int arr[] = {1, 4, 6};
E. All of these

Answer: All of these

Get the concepts clear at: How to declare and initialize an array in Java?

12. Which of the following is false about arrays in java?

a. A java array is always an object.


b. Length of array can be changed after creation of array
c. Array in java is always allocated in heap

Answer: Length of array can be changed after creation of array

Explanation: In Java, arrays are objects, they have members like length. The length
member is final and cannot be changed. All objects are allocated on heap in Java, so
arrays are also allocated on heap.

13. What is the extension of compiled java classes?


a. .txt
b. .js
c. .cass
d. .java

Answer: .class
14. What will be the output of the following Java program?
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Quiz");
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}

a) QuizziuQ
b) ziuQQuiz
c) Quiz
d) ziuQ
Answer: d
Explanation: reverse() method reverses all characters. It returns the reversed object on
which it was called.
Get the concepts clear at: https://www.studytonight.com/java/stringbuffer-class.php

15. Which of the following is false about the abstract classes in java?

a. If we derive an abstract class and do not implement all the abstract methods,
then the derived class should also be marked as abstract using 'abstract'
keyword.
b. Abstract classes can have constructors.
c. A class can be made abstract without any abstract method.
d. A class can inherit from multiple abstract classes.

Answer: A class can inherit from multiple abstract classes

16. What will be the output of the following Java code?

class Output
{
public static void main(String args[])
{
double x = 3.14;
int y = (int) Math.ceil(x);
System.out.print(y);
}
}
a. 3
b. 0
c. 4

Answer: 4

Explanation: ciel(double X) returns the smallest whole number greater than or equal to
variable x.

17. What will be the output of the following Java program?


import java.util.*;
class Arraylists
{
public static void main(String args[])
{
ArrayLists obj = new ArrayLists();
obj.add("A");
obj.add("B");
obj.add("C");
obj.add(1, "D");
System.out.println(obj);
}
}

a) [A, D, C]
b) [A, B, C]
c) [A, B, C, D]
d) [A, D, B, C]

Answer: [A, D, B, C]
Get the concepts clear at: https://www.baeldung.com/java-arraylist
Video: https://www.youtube.com/watch?v=NbYgm0r7u6o

18. What is the IEEE standard adopted to represent Floating point numbers in
Java?
a. IEEE9000
b. IEEE800
c. IEEE754
d. IEEE512

Answer: IEEE754

Explanation: IEEE stands for Institute of Electrical and Electronics Engineers. Original
specifications were defined in the year 1985. The current version includes
improvements or corrections done in the year 2008.

19. What is the character encoding standard used in Java language?

a. ASCII
b. Unicode
c. Hexacode
d. Bytecode

Answer: Unicode

Explanation: Unicode takes 2 Bytes (16 bits) of memory to represent all characters of
all languages.

20. Choose a correct rule for using Underscores in literals of Java language.
a. Underscores cannot come at the end of a number or next to the last digit of a
number.
b. Underscores cannot come at the beginning of a number or before the first digit of
a number.
c. Underscores cannot come before or after a decimal point in real numbers like
float and double.
d. All the above

Answer: All of the above


Explanation: There is no limit on the number of underscores between digits.

21. How do you rewrite the below java code snippet?

int p = 10;
P = p%3;

a. p=%3;
b. p%=3;
c. p=3%;
d. None of the above

Answer: p%=3;

22. Between Postfix and Prefix arithmetic operators in Java, which operators have
more priority?

a. Postfix operators have more priority over prefix operators


b. Prefix operators have more priority than postfix operators
c. Both postfix and prefix operators has equal priority
d. None of the above

Answer: Postfix operators have more priority over prefix operators.


Explanation: op++, op-- have more priority than --op, ++op.

23. Which keyword is used to inherit classes in Java?

A. extends
B. inheritance
C. isChild
D. None of these

Answer: A) extends

Explanation: The extends keyword is used to inherit classes in Java.

You might also like