0% found this document useful (0 votes)
79 views5 pages

Class 10 Key

The document contains questions and answers related to Java programming concepts. 1. It provides code snippets and questions to test understanding of loops, methods, variables, operators, and other Java concepts. 2. Detailed explanations and solutions are provided for converting loops, identifying variable types, distinguishing between static and non-static methods, and more. 3. Mathematical expressions and code snippets are used to demonstrate concepts like operator precedence, method overloading, and the law of conservation of energy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views5 pages

Class 10 Key

The document contains questions and answers related to Java programming concepts. 1. It provides code snippets and questions to test understanding of loops, methods, variables, operators, and other Java concepts. 2. Detailed explanations and solutions are provided for converting loops, identifying variable types, distinguishing between static and non-static methods, and more. 3. Mathematical expressions and code snippets are used to demonstrate concepts like operator precedence, method overloading, and the law of conservation of energy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Assertion (A): It can be used as a delay counter in which the loop executes for a predefined
number of times.
Reason (R): A Null loop is a loop that does not contain any instructions within itself.
A. Both A and R are true and R is the correct explanation for A.
2. The below is the picture given will be a perfect example of

D. Abstraction

3. double x=Math.min(Math.ceil(-19.78),Math.floor(-20.12)) - Math.abs(Math.round(-20.6));


math.min(-19,-21)-math.abs(-21)
-21-21= - 42.0
4. Assertion (A): <Access Modifier> class <class name>
Reason (R): The syntax to class as an object.
B. Both A and R are true, but R is not the correct explanation for A
5. Find out the exact sentence supporting the actual parameter.
D. Ex: sum(a, b);
6. Assertion (A): Constructors do not have any return type.
Reason (R): The implicit return type of a constructor is the class type itself.
A. Both A and R are true and R is the correct explanation for A.
7. What is the false sentence for Constructor?
c. A constructor has a same name of the class as the object name of the class
8. Statement I: Wrapper classes make it possible to use primitive values as objects that
can be used with any type of class and its methods.
Statement II: When Java automatically converts a primitive type into a corresponding wrapper
class object, like ink to integer, then it is called autoboxing.
A. I is true, II is true
9. Select which are true about the Access modifier – “Protected”
I. Within class II. Within Package
III. Outside Package by Subclass only IV. Outside Package
D. Only I, II and III
10. char toUppercase(char ch) --- Write the correct syntax for this method type.
D. char toUppercase(char ch)
11. What is the following does not include in Unary operator.
E. None of the above
12. x= x++ + x++ + ++x + x-- (if x=7) find the value
C. 35
13. 13. int n= (q-p)>(p-q)? (p-q):(q-p); (if p=5, q=19)
B. -14
14. 14. What is the output of the below java program that implements nesting of loops?
int i=1, j=1; A. 1,2,3,4,1,2,3,4
while(i<3) {
do { B. 1,2,3,4
System.out.print(j + ",");
j++; C. 1,2,3,1,2,3
} while(j<4);
i++; D. 1,2,3,1,2,3,1,2,3
}
B. 1,2,3,4
Explanation:
Do-WHILE works for the first-time printing (1,2,3). In the next iteration of i=2, the value of j is already 4. So
it is printed and checked for condition (j<4). The inner loop exits. In the third iteration with i=3, nothing is
printed.
15. Predict the output of the following code snippet: String P= “20”, Q= “22”
Int a = Integer.parseInt(P);
Int b = Integer.valueOf(Q);
System.out.println(a+ “ ” +b);
B. 20 22
16. The correct if statement for the following ternary operation statement i:
System.out.println(n%2==0? “true”: “false”);
C. if (n%2==0)
System.out.println(“true”);
else
System.out.println (“false”);
17. Is the below two lines legal Java code?
String str;
str = “Check for A Str.toUppercase(parse.string)”;
A. Yes
18. Answer the two below questions based on the below code snippet.
public class calculate {
void sum (int a, int b) {
System.out.println(“sum is” + (a+b)); }
void sum (double a, double b) {
System.out.println(“sum is” + (a+b)); }
public static void main(String args[]) {
calculate cal = new calculate();
cal.sum(20, 30);
cal.sum(14.6,13.8);
}}
What does the first line of output contain?
B. sum is 50
19. What can be the second line of output contain?
I. sum is 28.4 II. sum is 28.40 III. sum is 14.6 IV. Sum is 13.8
C. Both I and II
20. Match the following in order and find the correct sequence.
i. int parseInt(String s) a. it converts the character to lowercase.
ii. char toLowercase(char ch) b. It checks whether the character value is a letter or not and
returns true if the value is a letter, otherwise it returns false.
iii. boolean isLetter(char ch) c. The checks whether the character value ch is a letter or
digit, or not and returns true if the value is a letter or digit,
otherwise it returns false
iv. boolean d. This method belongs to the integer wrapper class. It
isLetterOrDigit(char ch) Converts a valid string representation of a numeric value into
a primitive integer value.
C. i-d, ii-a, iii-b, iv-c
Question 2 [20]
Answer in brief and less than 30minuites.

i. Convert the following do..while loop to for loop:


int x = 10;
do {
x--;
System.out.print(x);
} while(x>1);
Sol: for(int x= 10; x>=1;x--)
{
System.out.println(x);
}
ii. Consider the following program and answer the questions given below:
class sample {
int a, b; a. Name the Global variables
sample (int x, int y) used in the program that is
{ a=x; b= y; given
} Sol: a and b are global variables
void calculate() b. What are the method
{ variables used in the
int z; program that is given?
z = a+b; Sol: z is the method variable
System.out.println(z);
}
iii. What is the difference between static and non-static methods in a class?
Static methods belong to the class and are called by dereferencing the class name. For
example if there is a function abc() defined statically in the class Doable, then it is called as
Doable.abc()
Non-static methods are tied to objects Of the class and not the class itself. These methods
are called by use of the object. For example, if the variable representing the object is one,
then,
Doable one;
One = new Doable();
One.def();
The above code gives a method of calling the def() method of the object one.

iv. How are overload methods distinguished from each other?


They are distinguished from each other based on different argument lists passed to the
method. In the class definition, different versions of the function with the same name will
contain different definitions, in general.

v. Is it necessary to write the definition of a constructor with no arguments?


If you want to perform a specific set of operations, then you must put down as the
constructed definition. If you do not have anything in mind, you need not even define it, and
the normal in-built initializations of the object will take place anyway. However, for all
constructors with arguments, the definition must be provided. For constructors with
arguments, the definitions will not be provided by the complainer.

vi. b = a++ - ++a – a++ + b-- - --b + a++


when a= 5 and b =6, what are the outputs of a and b in the end of the operation?
b=5–7–7+6–4+8=1

vii.
−b+ √ b 2−4 ac
write the java expression for the given quadratic equation.
2a
X= (-b + Math.sqrt(Math.pow(b,2) – 4.0*a*c))/(2.0*a);
viii. class conv_energy {
static double PE (int m, int g, int h) {
return (m*g*h);
}
static double KE (double m, double v) {
return (0.5 *m*v*v); //enter the necessary formula for kinetic energy
}
public static void main (String args[]){
double x = PE(_any_,10,_any_); // fill in appropriate numbers g=10 has been substituted
double y = KE(10,5);
_double__ conv= x +y; // correct the statement and rewrite accordingly.
System.out.println(“Law of conservation of energy derived=” + ____conv__);
}}

ix. 1. ___Wrapper classes___are used to convert various primitive data types values to the
required data
types.
2. A ___Primitive__ data type can be encapsulated within an object using wrapper class.
3. The name of a wrapper class begins with a _____Uppercase letter____
4. Wrapper class are present in_____java.util______

Qurstion 3
Define a class to accept a number and output whether it is a Palindrome or not. Define a class with the
following specifications:
Class name:

You might also like