Java Basic - Quiz 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT

YELAHANKA – BANGALORE - 64
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Java Quiz- I
Marks :50 USN: Name: Date:

1) What is the range of data type short in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
View Answer

Answer:b

What is the output of this program?

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

Which of these is necessary condition for automatic type conversion in Java?


a) The destination type is smaller than source type.
b) The destination type is larger than source type.
c) The destination type can be larger or smaller than source type.
d) None of the mentioned
View Answer
Answer:b
Explanation:None.

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++;

What will be the value of "x" after execution ?

a) -2
b) -1
c) 0
d) 1

Answer 0

Java uses ___ to represent characters

a) ASCII code
b) Unicode
c) Byte code
d) None of the above

Answer b

5. Which one is not supported by OOP?

a) Abstraction
b) Polymorphism
c) Encapsulation
d) Global variables

Answer d

6. Java programs are


a) Platform-dependent
b) Interpreter-dependent
c) Platform-independent
d) Interpreter-independent

Answer c

The java compiler


a) creates executable
b) translates java source code to byte code
c) creates classes
d) produces java Interpreter

Answer b

The new operator


a) returns a pointer to a variable
b) creates a variable called new
c) obtains memory for a new variable
d) tells how much memory is available

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

10. Command to execute a compiled java program is :


a) javac
b) java
c) run
d) execute

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

What is the output of this program?

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

What is the output of this program?

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

What is the output of this program?

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

What is the output of this program?

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.

4. Which of these operators is used to allocate memory for an object in Java?


a) malloc
b) alloc
c) new
d) give
View Answer

Answer: c

What is the output of this program?

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

Which method can be defined only once in a program?


a) main method
b) finalize method
c) static method
d) private method
View Answer

Answer: a

What is the return type of Constructors?


a) int
b) float
c) void
d) None of the mentioned
View Answer

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

What is the output of this program?

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

What is the output of this program?

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

How many access specifiers are there in c++?


a) 1
b) 2
c) 3
d) 4
Answer:c

What of the following describes protected access specifier?


a) The variable is visible only outside inside the block
b) The variable is visible everywhere
c) The variable is visible to its block and to it’s derived class
d) None of the mentioned
View Answer

Answer:c

Pick out the correct statement.


a) A friend function may be a member of another class.
b) A friend function may not be a member of another class.
c) A friend function may or may not be a member of another class.
d) None of the mentioned
View Answer

Answer:c
Explanation:None.

10. Where does keyword ‘friend’ should be placed?


a) function declaration
b) function definition
c) main function
d) None of the mentioned
View Answer
Answer:a

How to access the object in the class?


a) scope resolution operator
b) ternary operator
c) direct member access operator
d) none of the mentioned
View Answer

Answer:c

Pick out the other definition of objects.


a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class
View Answer

Answer:d

Which operator is used to signify the namespace?


a) conditional operator
b) ternary operator
c) scope operator
d) none of the mentioned
View Answer

Answer:c

Which keyword is used to access the variable in namespace?


a) using
b) dynamic
c) const
d) static
View Answer

Answer:a

Which of the following permits function overloading on c++?


a) type
b) number of arguments
c) both of the mentioned
d) none of the mentioned
View Answer

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.

3. Function overloading is also similar to which of the following?


a) operator overloading
b) constructor overloading
c) destructor overloading
d) none of the mentioned
View Answer

Answer:b

Which value we cannot assign to reference?


a) integer
b) floating
c) unsigned
d) null
View Answer

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

Constructs new data type


Enables the initialization of an object as it is created
Obtain memory for a new variable
None of the above

42) When a copy of an entire object is passed to a function, then it is referred to as

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

ANSWER: cout << * < P;

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

Answer: A. Static variables, non static 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?

a) Class C is friend of class A


b) Class A is friend of class C
c) Class A and Class C do not have any friend relationship
d) None of the above
Answer b

What is meant by ofstream in c++?


a) Writes to a file
b) Reads from a file
c) Both a & b
d) None of the mentioned
View Answer

Answer:a

Where does a cin stops it extraction of data?


a) By seeing a blankspace
b) By seeing (
c) Both a & b
d) None of the mentioned
View Answer

Answer:a

How many objects can present in a single class?


a) 1
b) 2
c) 3
d) as many as possible
View Answer

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

Static variable declared in a class are also called_________

a. instance variable
b. named constant
c. global variable
d. class variable
View Answer / Hide Answer

ANSWER: d. class variable

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

Signature of the student

You might also like