Java Basic - Quiz 1
Java Basic - Quiz 1
Java Basic - Quiz 1
YELAHANKA – BANGALORE - 64
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Java Quiz- I
Marks :50 USN: Name: Date:
Answer:b
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300
View Answer
Answer:b
If an expression contains double, int, float, long, then whole expression will promoted into which
of these data types?
a) long
b) int
c) double
d) float
View Answer
Answer: c
int x = 0, y = 0 , z = 0 ;
x = (++x + y-- ) * z++;
a) -2
b) -1
c) 0
d) 1
Answer 0
a) ASCII code
b) Unicode
c) Byte code
d) None of the above
Answer b
a) Abstraction
b) Polymorphism
c) Encapsulation
d) Global variables
Answer d
Answer c
Answer b
Answer c
8. Which of the following statement is correct?
a) For positive numbers, result of operators >> and >>> are same
b) Java provides two operators to do left shift <<< and <<
c) >> is the zero fill right shift operator
d) >>> is the signed right shift operator
Answer a
9. Java language has support for which of the following types of comment?
a) block, line and javadoc
b) javadoc, literal and string
c) javadoc, char and string
d) single, multiple and quote
Answer a
Answer b
Modulus operator, %, can be applied to which of these?
a) Integers
b) Floating – point numbers
c) Both Integers and floating – point numbers.
d) None of the mentioned
View Answer
Answer:c
1. class increment {
2. public static void main(String args[])
3. {
4. double var1 = 1 + 5;
5. double var2 = var1 / 4;
6. int var3 = 1 + 5;
7. int var4 = var3 / 4;
8. System.out.print(var2 + " " + var4);
9.
10. }
11. }
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0
View Answer
Answer:c
1. class increment {
2. public static void main(String args[])
3. {
4. int g = 3;
5. System.out.print(++g * 8);
6. }
7. }
a) 25
b) 24
c) 32
d) 33
View Answer
Answer:c
1. class ternary_operator {
2. public static void main(String args[])
3. {
4. int x = 3;
5. int y = ~ x;
6. int z;
7. z = x > y ? x : y;
8. System.out.print(z);
9. }
10. }
a) 0
b) 1
c) 3
d) -4
View Answer
Answer:c
1. class Output {
2. public static void main(String args[])
3. {
4. int x , y = 1;
5. x = 10;
6. if (x != 10 && x / 0 == 0)
7. System.out.println(y);
8. else
9. System.out.println(++y);
10. }
11. }
a) 1
b) 2
c) Runtime error owing to division by zero in if condition.
d) Unpredictable behavior of program.
View Answer
Answer: b
Which of the following is a valid declaration of an object of class Box in Java?
a) Box obj = new Box();
b) Box obj = new Box;
c) obj = new Box();
d) new Box obj;
View Answer
Answer: a
Explanation: None.
Answer: c
1. class box {
2. int width;
3. int height;
4. int length;
5. }
6. class mainclass {
7. public static void main(String args[])
8. {
9. box obj1 = new box();
10. box obj2 = new box();
11. obj1.height = 1;
12. obj1.length = 2;
13. obj1.width = 1;
14. obj2 = obj1;
15. System.out.println(obj2.height);
16. }
17. }
a) 1
b) 2
c) Runtime error
d) Garbage value
View Answer
Answer: a
What is the process of defining more than one method in a class differentiated by method
signature?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned
View Answer
Answer:b
Which of the following is a method having same name as that of it’s class?
a) finalize
b) delete
c) class
d) constructor
View Answer
Answer: d
Answer: a
Answer: d
Which keyword is used by method to refer to the object that invoked it?
a) import
b) catch
c) abstract
d) this
View Answer
Answer: d
Which of these selection statements test only for equality?
a) if
b) switch
c) if & switch
d) None of the mentioned
View Answer
Answer: b
Which of these jump statements can skip processing remainder of code in its body for a
particular iteration?
a) break
b) return
c) exit
d) continue
View Answer
Answer: d
1. class comma_operator {
2. public static void main(String args[])
3. {
4. int sum = 0;
5. for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
6. sum += i;
7. System.out.println(sum);
8. }
9. }
a) 5
b) 6
c) 14
d) compilation error
View Answer
Answer: b
1. class jump_statments {
2. public static void main(String args[])
3. {
4. int x = 2;
5. int y = 0;
6. for ( ; y < 10; ++y) {
7. if (y % x == 0)
8. continue;
9. else if (y == 8)
10. break;
11. else
12. System.out.print(y + " ");
13. }
14. }
15. }
a) 1 3 5 7
b) 2 4 6 8
c) 1 3 5 7 9
d) 1 2 3 4 5 6 7 8 9
View Answer
Answer:c
Answer:c
Answer:c
Explanation:None.
Answer:c
Answer:d
Answer:c
Answer:a
Answer:c
In which of the following we cannot overload the function?
a) return function
b) caller
c) called function
d) none of the mentioned
View Answer
Answer:a
Explanation:While overloading the return function, it will rise a error, So we can’t overload the
return function.
Answer:b
Answer:d
Identify the correct sentence regarding inequality between reference and pointer.
a) we can not create the array of reference.
b) we can create the Array of reference.
c) we can use reference to reference.
d) none of the mentioned
View Answer
Answer:a
Which value will it take when both user and default values are given?
a) user value
b) default value
c) custom value
d) none of the mentioned
View Answer
Answer:a
41) A constructor
Pass-by-reference
Pass-by-pointer
Pass-by-value
None of the above
View Answer / Hide Answer
ANSWER: Pass-by-value
43) You have assigned the address of Value to the pointer P, Which statement will display the
value stored in Value?
cout << P;
cout << *Value;
cout << &P;
cout << * < P;
View Answer / Hide Answer
44) Objects of the same class share the values of ...... while they maintain separate values for .....
[A] Static variables, non static variables
[B] Non static variables, static variables
[C] Global variables, static variables
[D] Static variables, register variables
45) If class A is friend of class B and if class B is friend of class C, which of the following is true?
Answer:a
Answer:a
Answer:d
Default value of static variable is_____
a. 0
b. 1
c. Garbage value
d. Compiler dependent
View Answer / Hide Answer
ANSWER: a. 0
a. instance variable
b. named constant
c. global variable
d. class variable
View Answer / Hide Answer
C structure differs from CPP class in regards that by default all the members of the structure
are__________ in nature.
a. private
b. protected
c. public
d. None of these
View Answer / Hide Answer
ANSWER: c. public