Comp Question Paper HFE
Comp Question Paper HFE
Comp Question Paper HFE
______________________________________________________________________________________________
This paper is divided into two Sections.
Attempt all questions from Section A and any four questions from Section B.
The intended marks for questions or parts of questions are given in brackets [ ].
______________________________________________________________________________________________
SWARN
(a) Data abstraction (b) Polymorphism (c) Inheritance (d) Encapsulation
(ii) The extension of byte code is:
(a) .class (b) .obj (c) .java (d) .exe
(iii) Java made web interesting as it makes it:
(a) interpreted (b) interactive (c) platform independent (d) None of these
(iv) An object is represented by two attributes, out of which one is characteristics and the other one is:
(a) behaviour (b) situation (c) abstraction (d) problem solving
(v) The method used by objects to interact with each other is known as:
(a) Message interaction (b) Object communication (c) Message passing (d) None of these
(vi) The range of byte data type is:
(a) -128 to 128 (b) -128 to 127 (c) -127 to 127 (d) -127 to 128
Page 1 of 5
(vii) Predict the output:
boolean x = true;
System.out.println((int) x);
(a) 1 (b) 0 (c) true (d) Syntax error
Sometimes a program may compile properly and seems perfect with the logic. But certain abnormal
situation may arise in the code sequence at run-time. This is called an exception or run-time error.
(xv) Assertion (A): Relational operators are used for comparison between two data items that are used in
a test expression.
Reason (R): An expression with relational operator will always result in either true or false to represent
a success or failure.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
(xvi) The evaluated value of the expression a > b || a > c (where a = 10 , b = 8 and c = 20) is:
(a) true (b) false Page 2 of 5
(xvii) Assertion (A): Logical operators can be used to join more than one relational expression
Reason (R): Logical operators are binary in nature
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of
Assertion (A)
(c) Assertion (A) is false and Reason (R) is true
(d) Assertion (A) is true and Reason (R) is false
(xviii) The first operand that a ternary operator deals with is:
(a) test expression (b) Expression 1 (c) Expression 2 (d) any one of these
(xix) nextInt() is a method of a class included in:
(a) java.lang (b) java.io (c) java.util (d) None of these.
Question 2
Answer the following questions (working must be shown if required):
(ii) Write a Java expression for the following mathematical expression: [2]
c = 𝑥√𝑦
(iii) Write the syntax of if-else with else if ladder considering three possible outcomes. [2]
x = x– – + x++ / – –x;
(ix) Write two differences between if-else and switch-case statements. [2]
(x) Rewrite the following code fragment using if-else statement: [2]
Question 3
Write a javaa program
(i) Write program to to input
inputtwo
a number
integers(Num) and print
as arguments to all factors main()
a method of Num, in find
and descending
their sumorder
without
and their sum, in following format-
using the addition operator (‘+’). Print the result with a proper message. [8]
Sample Input/Output:
(ii) Write a program to accept three integers as arguments to a method main() and evaluate the product
of their last digits. Print theInput
result: with a proper message. [7]
10
Output :
10 + 5 + 2 + 1 = 18
Question 4
(i) Write a program to input the radius of a semicircle using a Scanner class input method and evaluate
its perimeter as well as area. Display the outputs in separate lines with proper messages. [8]
(ii) Write a program to input three integers using a Scanner class input method and display the smallest
number with a proper message. [7]
Question 5
(i) Write a program to input a real number (floating-point number) using a Scanner class input method
and round it off to the nearest integer without using any Mathematical library method and conditional
statement. Display the result with an appropriate message. [8]
(ii) Write a program to input a digit character using a Scanner class input method and using switch-case
statement display the name of the digit. [7]
Question 6
(i) Write a program to accept two integers as arguments to a method main() and swap their values
without using a third variable. Display the result in suitable format. [8]
(ii) Write a program to input an integer (positive or negative) as argument to a method main() and check
whether it is a 4-digit number or not. [7]
Question 7
(i) Write a menu-driven program using switch case to perform the following operations as per a choice
selected by the user (use Scanner class input methods): [8]
Page 4 of 5
(a) Accept two numbers and print the sum of their absolute values.
(b) Accept two numbers and display the first number raised to the power of second number.
Also display an error message if the user opts for an invalid choice.
(ii) Write a program to accept the perimeter of a square and evaluate its area. Display the output with a
suitable message. [7]
Question 8
To foster a sense of water conservation, the water department has an annual conservation tax policy.
The taxes are based on the water consumption of the consumer. The tax rates are as follows: [15]
Upto 40 No Tax
Write a program to input the consumer id and water consumed annually in gallons and display the
output in the following format:
Page 5 of 5