WorksheetsWeek 2
Total questions: 25
Worksheet time: 1hrs 5mins
Which of the following statements is/are true about the statement given below?
String args[ ] is used to handle the command line arguments.
static keyword allows calling the main method without using any object.
The void keyword specifies that main does not return any value.
The public keyword is an access modifier. It restricts the main method to be accessed from outside the program.
Which of the following statements is/are true about data types in Java?
Statement 1: int and byte data types allows numbers/numeric values with fractions.
Statement 2: long and double data types does not allow numbers/numeric values with fractions. Statement 3: byte and short, data types does not allow numbers/numeric values with fractions.
Statements 1, 2 and 3 are correct.
Statement 1 and 2 are correct.
Only statement 2 is correct.
Only statement 3 is correct.
Consider the variable declarations given below, and select the correct option.
int age=47;
int pincode=508206;
int days_of_a_week=7;
int hours_of_a_day=24;
We can make variable age as final as it may be changed person to person.
We cannot make variable days_of_a_week as final as its value must be constant.
We can make variable hours_of_a_day as final as it is constant.
We can not make variable pincode as final as it may be changed city to city.
Consider the Java code given below and predict the output.
99
50
101
100
Consider the Java code given below and predict the output.
4
5
16
3
4
12
4
5
20
4
4
16
The _____________modifier indicates a constant.
static
public
constant
final
Identify the correct piece of code and choose the correct option.
I. int a = (int)999.9;
II. byte b = (byte)500L;
III. long c = (byte)50;
IV. long d = 50;
The above all statements are correct.
IV
I and II
III
Runtime Error
First Number: Null Second Number: Null
Compilation Error
First Number: 0 Second Number: 0
A-III, B-II, C-IV, D-I
A-II, B-I, C-III, D-IV
A-I, B-IV, C-II, D-III
A-II, B-III, C-I, D-IV
How is it possible to run the main method in Java without creating an object?
The access modifier public helps the main() method to run independently without creating an object.
The main() method is an exception. It is the only method that exist independently without the dynamic creation of an object.
The modifier static helps the main() method to run independently without creating an object.
Java is an object oriented programming language. Thus we need to create an object of the main class, and call our main() method to run. Hence the question is fallacious.
Considering the following Java code, choose the correct statement from among the given options regarding this code.
The code results in a compilation error as eid and ename instance variables should be initialized before using them.
The code results in a compilation error as constructor is not defined.
Program runs successfully, and the data members eid and ename contains random garbage value.
Program runs successfully, and the data members eid and ename contains 0 and null respectively.
Consider the statements given below and select the correct option.
Statement 1: Iterative statements allow your program to choose different paths of execution based upon the outcome of an expression or the state of a variable.
Statement 2:Selection/Conditional statements enable program execution to repeat one or more statements.
Statement 1 correct and 2 incorrect.
Statement 1 incorrect and 2 is correct.
Statement 1 and 2 are correct.
Statement 1 and 2 are incorrect.
Consider the Java code given below and predict the output.
Hello World! printed forever.
Compilation fails due to error in line no 5.
Nothing will be printed.
1010
Consider the java code given below and predict the output.
00
11
22
33
0
1
2
3
Compilation fails.
Generates no output.
Which of the following loops will execute the body of loop even if the controlling state ment of the loop is false?
for-each
for
do-while
while
What will be the output/error?
Compilation fails due to System.out.println(10+20+"IIT Madras");
Compilation fails due to System.out.println("IIT Madras"+10+20);
30IIT Madras
IIT Madras1020
Exception at run time.
Which of the following data type follows the object oriented paradigm in Java?
int
float
String
boolean
Consider the Java code given below and predict the output.
Hello World! printed 10 times.
Hello World! printed 9 times.
Compilation fails due to error in line no 6.
Hello World! printed until stack over ow.
Consider the Java code given below and predict the output.
Compilation fails
Generates no output
Print numbers from 0 to 9 as output.
0
Consider the java code given below and predict the output.
0
001
112
223
33
0
1
2
3
Generates no output.
Compilation fails.
Consider the Java code given below.
What will the output be if we provide Sri Lanka as the input for the program?
Delhi is capital of India.
Colombo is capital of Sri Lanka.
Please enter valid country name:
Colombo is capital of Sri Lanka
Please enter valid country name:
Colombo is capital of India.
Compilation fails.
Consider the Java code given below.
The code generates a compilation error.
The code generates a run time error.
Nothing will be printed.
Hello World! would be printed forever.
Consider the Java code given below.
compilation failed.
30
20
10
Consider the Java code given below.
Choose the correct option regarding the given code.
Generates output :
0
0
Generates a compilation error
Generates output : 0
Generates no output but program compiles successfully.
