1. In Java the statement used to tell the compiler that the current source file
ID: 3739499 • Letter: 1
Question
1. In Java the statement used to tell the compiler that the current source file is using classes from a specified package is ______________.
a. include
b. access
c. library
d. import
e. none of the above
2. Comments containing more than one line are most efficiently coded in Java:
a. between double quotes
b. after //
c. between /* and /*
d. between * and *
e. none of the above
3. To assign the value in age to the variable max_age in Java use ____________.
a. max_age = age;
b. max_age equals age;
c. max_age == age;
d. age = max _age;
e. none of the above
4. What data type does the Java readLine() method input?
a. String
b. decimal
c. integer
d. character
e. none of the above
5. In Java the following will output the decimal value of the variable pay with the label Pay is :
a. System.out.println("pay" + Pay is :);
b. System.out.Output("Pay is :" + pay);
c. System.out.println("Pay is :" + pay);
d. System.out print[label("Pay is :") + pay];
e. none of the above
6. Which of the following conditions would have a true value when age and 33 are equal in Java?
a. (age equals 33)
b. (age == 33)
c. (age != 33)
d. (age = 33)
e. none of the above
7. Which of the following conditions would have a true value when age and 33 are unequal in Java?
a. (age equals 33)
b. (age == 33)
c. (age != 33)
d. (age = 33)
e. none of the above
8. In Java, a method is ______________.
a. an operator
b. a module
c. always main()
d. an invocation
e. none of the above
9. Given that k = 0 initially, what is the value of k after execution of the java instruction
while(k <= 5)
{
k = k + 1;
}
a. 0
b. 1
c. 5
d. 6
e. none of the above
10. Given that k = 0 initially, what is the value of k after execution of the java instruction
if(k <= 5)
{
k = k + 1;
}
a. 0
b. 1
c. 5
d. 6
e. none of the above
Explanation / Answer
1. In Java the statement used to tell the compiler that the current source file is using classes from a specified package is ______________.
Ans--d. import
import keyword is used to import biult-in and user-defined packeges in the java code to refer the classes from the package.
e.g import java.util.Scanner;
If we use this import statement we can only refer the Scanner class in source code.
e.g import java.util.*;
If we use this import statement we can use all classes and interfaces from the java.util package.
2. Comments containing more than one line are most efficiently coded in Java:
Ans-e. none of the above
The multiline comments in java are between /* and */ .
Multiline comment starts from /* (that is forward slash followed by star symbol) and ends at */ (that is star symbol followed by forward slash).
// is used for single line comment in java
e.g- /* line1------
line2---------------
---------------
line n------- */
3. To assign the value in age to the variable max_age in Java use ____________.
Ans-a. max_age = age;
In java the variable to assign is written in left side of the equal to sign and the value is written at right side of the equal to sign.
Syntax- variable_name = value ;
In the above situation we want to assign the variable max_age .And value is in the age;
e.g- we want to assign value 10 to the variable x then
x = 10 ;
4. What data type does the Java readLine() method input?
Ans- a. String
readLine() method reads the one line string input in java
In other hand read() method reads single character input in java
e.g- BufferedReader br=new BufferedReader(new InputStreamReader(System.in))
String str = br,readLine();
5. In Java the following will output the decimal value of the variable pay with the label Pay is :
Ans- c. System.out.println("Pay is :" + pay);
In java System.out.print() AND System.out.println() methods are used to display output in console.
The string output is enclosed in double quotes but the variable values are printed without any quotes.
Two different types of data is concated by using + operator. + is used as a concatnation operator in this method.
In the above example "pay is" is a label and pay is a variable.
e.g- If we want to print value in variable x the
System.out.println("Value of a is= " + a);
6. Which of the following conditions would have a true value when age and 33 are equal in Java?
Ans- b. (age == 33)
For cheking equality of two values or variables in java == operator is used.So we have to use == operator in condition.
we can not use != or = operators to check equality.
!= operator is used to check inequality and = operator is used to initialization in java.
7. Which of the following conditions would have a true value when age and 33 are unequal in Java?
Ans- c. (age != 33)
As i said in prevoius answer != operator is used for checking inequality in java.We have to use != opeartor in the condition.
8. In Java, a method is ______________.
Ans- b. a module
Module is a unit of a organisation in which internal details are hidden..
In java methods are module because the variables and code in the method is hidden..
In java classes are also mosules because data inside the classes are also hidden.
Module can be divided into sub parts . in java classes have methods.
9. Given that k = 0 initially, what is the value of k after execution of the java instruction
while(k <= 5)
{
k = k + 1;
}
Ans- d. 6
In the above example k is initialized with ...
Rule of while loop is it checks condition firstly . if condtion becomes true then body of while loop executed.
this continues until condition bacomes false;
here k=0;
while checks if k <= 5 or not . it means 0 <=5 .this condition is true.
in body of loop value of k in increased by 1.
Now k=1
this continues until k becomes 5.
when k=5;
it executes loop body and k becomes 6.
and then contion becomes false. 6<=5.
So value of k is 6.
10. Given that k = 0 initially, what is the value of k after execution of the java instruction
if(k <= 5)
{
k = k + 1;
}
Ans-b. 1
In the above example
k=0
if condition checks the conditions only once.
here condition is 0<=5 is true
and k is incremented by 1.
so k becomes 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.