Practice Question For COS 201
Practice Question For COS 201
A) Functional
B) Object-Oriented
C) Theoretical
Answer B
A) Classes, Interfaces
B) Methods
C) Blocks
Answer D
A) Methods
B) Variables
C) Interfaces
Answer B
A) Prototype
B) Instruction Sheet
C) Blueprint
Answer D
5) Which is the file extension used for a public Java class source code?
A) .j
B) .class
C) .java
D) None
Answer C
6) Which is the file extension used for a compiled Java class file?
A) .j
B) .java
C) .class
D) .cls
Answer C
A) FALSE
B) TRUE
C) -
D) -
Answer B
A) .java
B) .cls
C) .class
D) .interface
Answer C
Explanation: All compiled Java classes, interfaces and abstract classes are kept in a .class
file only. All source files are kept in .java files.
9) State TRUE or FALSE. In Java, a public class or abstract-class or interface must be kept in
a separate .java file.
A) FALSE
B) TRUE
C) -
D) -
Answer B
10) In a .java file, how many numbers of public types namely class, interface or abstract can
be managed?
A) 1
B) 2
C) 3
D) Any number
Answer A
Explanation:
A) Class
B) Java
C) class
D) java
Answer C
A) Variables
B) Methods, Constructors
Answer D
13) How many maximum numbers of objects can be created from a single Class in Java?
A) 32
B) 64
C) 256
D) None
Answer D
Explanation:
A) Initializing
B) Instantiating
C) Interfacing
Answer B
A) class
B) java
C) new
D) create
Answer C
16) Choose the correct statements about choosing a name for a class in Java.
A) The class name can start with only a letter or underscore or dollar sign.
Answer D
Explanation:
A) Compile-time
B) Run time
C) Assembling time
Answer B
C) You can define program flow using the main method. The Java virtual machine calls the
main method directly.
Answer D
Explanation:
19) Choose the correct syntax for declaring a Java class below.
A)
class CLASSNAME
B)
CLASSNAME class
C)
class CLASSNAME;
D)
Class CLASSNAME
Answer A
Explanation:
20) Choose the correct way of creating an object of the below class.
class Table
Table(){System.out.println("Table Created");}
A)
B)
C)
Answer B
A) Same
B) Different
C) -
D) -
Answer A
A) Primitive
B) Object
C) -
D) -
Answer B
Explanation:
A) Names
B) Values
D) None
Answer C
B) Allocates memory
C) -
D) -
Answer A
A) -1
B) 0
C) 1
D) Any integer
Answer B
A) Braces { }
B) Parentheses ()
C) Square Brackets [ ]
Answer C
7) Which are the special symbols used to initialize an array at the time of the declaration
itself?
A) Parentheses ( )
B) Square Brackets [ ]
C) Braces { }
Answer C
Explanation:
8) It is possible to skip initializing some elements of the array during Shorthand Initialization.
(TRUE / FALSE)
A) FALSE
B) TRUE
C) -
D) -
Answer A
Explanation:
No, you cannot skip any elements. All elements need to be initialized in one go or at the
same time.
9) In Java, an array can be declared without initialization without mentioning the size. (TRUE
/ FALSE)
A) TRUE
B) FALSE
C) -
D) -
Answer A
Explanation:
10) What is the output of the below Java code snippet with arrays?
System.out.println(nums.length);
A) 0
B) null
C) Compiler error
Answer D
A) 2,65
B) 3,95
C) 3,65
D) Compiler error
Answer C
Explanation:
Array index starts with Zero (0). So marks[1] represents the second element.
System.out.print(balls.length);
A) 0
B) -1
C) 1
D) Compiler error
Answer A
A)
//int[] ary;
ary.length()
B)
//int[] ary;
ary.length
C)
//int[] ary;
ary->length()
D)
//int[] ary;
ary->length
Answer B
Explanation:
System.out.print(colors[2]);
A) RED
B) YELLOW
C) WHITE
D) Compiler error
Answer D
Explanation:
15) What is the output of the below Java program with arrays?
System.out.print(parts[1]);
A) RAM
B) HDD
C) MOUSE
D) Compiler error
Answer C
System.out.println(ages[1]);
A) 25
B) 27
C) 30
D) Compile error
Answer D
Explanation:
We should not mention the array size at the time of Shorthand Initialization.
So make it like
17) We should not specify the array size if declaration and initialization are done at the same
time. (TRUE / FALSE)
A) FALSE
B) TRUE
C) -
D) -
Answer B
Explanation:
WRONG:
int ary[2]={34,45};
RIGHT:
A) N-1
B) N
C) N+1
D) N+2
Answer C
Explanation:
Array index starts with 0. So, an index of 6 means 7th position. An index of N means,
N+1 position.
19) An array in Java can be declared only of some predefined types. (TRUE/FALSE)
A) FALSE
B) TRUE
C) -
D) -
Answer A
Explanation:
20) The name of an array variable or identifier can start with ___.
A) A letter
B) Underscore ( _ )
D) All
Answer D
21) Shorthand array initialization in Java needs the keyword "new" to allocate memory to the
array and elements. State TRUE or FALSE.
A) FALSE
B) TRUE
C) -
D) -
Answer A
Explanation:
Only lazy initialization of array needs the keyword "new" to allocate memory.
22) Lazy initialization of array requires the keyword "new" to allocate memory to the array
and its elements. State TRUE or FALSE.
A) FALSE
B) TRUE
C) -
D) -
Answer B
Explanation:
int[] ary;
A) 0
B) null
C) -1
D) Garbage value
Answer B
Explanation:
24) What is the default value of byte, short, int or long data type elements of an array in Java?
A) -1
B) 1
C) 0
D) Garbage value
Answer C
25) What is the default value of float or double data type elements of an array in Java?
A) 0
B) 0.0
C) 1
D) 1.0
Answer B
26) What is the default value of a char data type elements of an array in Java?
A) 'A'
B) '\0'
C) null
D) '\0' or null
Answer D
Explanation:
27) What is the default value of boolean data type elements of an array in Java?
A) true
B) false
C) -
D) -
Answer B
28) Allocating memory with the keyword "new" causes the array elements to carry default
values. State TRUE or FALSE.
A) FALSE
B) TRUE
C) -
D) -
Answer B
balls[i] = (i+1)*2;
System.out.print(balls[j] + ",");
A) 0,2,4,
B) 1,2,3,
C) 2,4,6,
D) Compiler error
Answer C
30) What is the output of the below Java program with arrays?
ary[1] = str;
str = "FLY";
System.out.println(ary[1]);
A) AIR
B) PLANE
C) FLY
D) Compiler error
Answer B
A) Bidirectional
B) Combo
C) Multidimensional
D) Multi-value
Answer C
32) A multidimensional array contains elements of the same data-type in all rows and
columns. State TRUE or FALSE.
A) FALSE
B) TRUE
C) -
D) -
Answer B
A) N-1
B) N
C) N+1
D) 10*N
Answer B
34) An array with two dimensions is called a two-dimensional array in Java. State TRUE or
FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer A
35) Row number and Column number in a Multidimensional array start with ___.
A) -1
B) 0
C) 1
D) 2
Answer B
A) 4
B) 3
C) 2
D) 1
Answer B
Explanation:
A)
B)
C)
int[][] code={1,2,
3,4,5};
D) All
Answer A
Explanation:
38) What is the output of the Java program with the multidimensional array?
int[][] goats;
goats[0] = {1,2};
System.out.println(goats[0][1]);
A) 0
B) 1
C) 2
D) Compiler error
Answer D
Explanation:
It is lazy initialization.
goats[0][0] = 1;
goats[0][1]=2;
System.out.println(goats[0][1]);
//Output: 2
39) State TRUE or FALSE. In a multidimensional array, the number of Columns in each
Row can be different.
23
456
A) FALSE
B) TRUE
C) -
D) -
Answer B
40) While mentioning the array size in a multidimensional array using the new keyword, the
left-most script is mandatory. State TRUE or FALSE.
int ary[][];
A) FALSE
B) TRUE
C) -
D) -
Answer B