WorksheetsJava Basics
Total questions: 15
Worksheet time: 10mins
___________ is a collection of elements used to store the same type of data.
Array
Switch
Case
Loop
For the array: int a[3]; What is the range of the index?
0 to 3
0 to 2
1 to 3
0 to 4
Create an array of 12 strings called months
(a)
What is the correct way to create an array with these 3 numbers: 12 8 15
int[] = {12,8,15};
int[] nums = { 12 8 15 };
int[] nums = {12,8,15}
int[] nums = {12,8,15};
An array can store different types of data like double and ints
True
False
Which of the following is a valid variable declaration in Java?
int 1myinteger=0;
int int=0;
Int my Integer=0;
int myIntger=0;
The import statement used to access the Scanner class is:
(a)
Is String a primitive datatype?
Yes
No
Both
Which datatype gets returned from length() method in String class?
double
number
String
int
What will be the output of
System.out.println("Computer".substring(3,6));
(a)
What is the return type of equalsIgnorecase() method?
int
boolean
char
String
What is the most appropriate way to check if 2 strings are identical?
str1 == str2
str1.equals(str2)
str1.same(str2)
str1.equalsIgnorecase(str2)
Scanner s = new Scanner(System.in);
int a = (a) ;
User Defined Exceptions are sub classes of the base class
SystemException
Exception
MyException
None of the above
Where do we close all objects?
try block
catch block
finally block
anywhere - doesn't matter
