Reference no: EM133161265
Object Oriented Concepts
Question 1. Which of the following commands allows you to create the file named Hello.class containing the bytes of code that will have to be loaded into memory during its execution:
a) java Hello
b) java Hello.java
c) javac Hello.java
d) javac Hello.html
Question 2. Which of the following statements will display the chain Hello World?
a) System.out.printf( "%2s", "Hello" "Word" );
b) System.out.printf( "%s %s %s", "Hello", "World" );
c) System.out.printf( "%s%s%s", "Hello, World" );
d) System.out.printf("s% s% %s", "Hello" "le" "World" );
Question 3. What is the result of this program? public class OpIncr
{
public static void main(String[] args)
{ int i, j, n ;
i = 0 ; n = i++ ;
System.out.println ("A : i = " + i + " n = " + n ) ;
i = 10 ; n = ++ i ;
System.out.println ("B : i = " + i + " n = " + n ) ;
i = 20 ; j = 5 ; n = i++ * ++ j ;
System.out.println ("C : i = " + i + " j = " + j + " n = " + n ) ;
} }
a) A : i = 0 n = 1 B
: i = 11 n = 11
C : i = 21 j = 6 n = 120
b) A : i = 1 n = 0
B : i = 11 n = 11
C : i = 21 j = 6 n = 120
c) A : i = 1 n = 0 B : i = 0 n = 11
C : i = 20 j = 6 n = 120
d) A: i = 1 n = 1
B : i = 11 n = 11
C : i = 21 j = 6 n = 140
Question 4. What is the value of the result variable after executing the following Java statements?
int a, b, c, d, result; a = 4;
b = 12;
c = 37;
d = 51;
result = d % a * c + a % b + a;
a) 119
b) 51
c) 127
d) 59
Question 5. Which of the following is not a syntax error?
a) Forgetting to initialize a local variable in a method before using it.
b) Using only one = symbol instead of two in an if statement.
c) Adding a semi-colon (;) at the end of the first line of an if statement.
d) Forgetting to put the left and right parentheses in an if statement.
Question 6. Every Java application is made up of at least on of the following:
a) public method
b) data members
c) Defining a public class
d) an imported class
Question 7. From the following choices, which is a name that is entirely qualified and that allows us to access the methods of a Scanner object?
a) Scanner
b) java.Scanner
c) util.Scanner
d) java.util.Scanner
Question 8. What is the result of the following Java Code?
int temp; temp = 200;
if ( temp > 90 )
System.out.println( "This coffee is too hot." );
if ( temp < 70 )
System.out.println( "This coffee is too cold." );
if ( temp == 80 )
System.out.println( "This coffee is perfect!" );
a) This coffee is too hot.
b) This coffee is too cold.
c) This coffee is perfect!
d) Non of the above.
Question 9. What is the result of the following Java code?
int temp; temp = 180;
while ( temp != 80 )
{
if ( temp > 90 )
{
System.out.print( "This coffee is too hot! " ); temp = temp - ( temp > 150 ? 100 : 20 );
}
else
{
if ( temp < 70 )
{
System.out.print(
"This coffee is too cold! ");
temp = temp + (temp < 50 ? 30 : 20);
}
}
}
if ( temp == 80 )
System.out.println( "This coffee is perfect!" );
a) This coffee is too cold! This coffee is perfect!
b) This coffee is too hot! This coffee is perfect!
c) This coffee is perfect!
d) None of the above.
Question 10. Which of the following will count down from 10 to 1 correctly?
a) for ( int j = 10; j <= 1; j++ )
b) for ( int j = 1; j <= 10; j++ )
c) for ( int j = 10; j > 1; j-- )
d) for ( int j = 10; j >= 1; j--)
Question 11. Which of the following statements is true with respect to a do...while statement?
a) The body of the do...while loop will be executed only if the result is true.
b) The body of the do...while loop will only be executed once.
c) The body of the do...while loop will always be executed at least once.
d) None of these answers
Question 12. In the following segment of code, what value of the q variable will yield the display of the word kiwi?
switch( q )
{ case 1:
System.out.println( "apple" ); break;
case 2:
System.out.println( "orange" ); break;
case 3:
System.out.println( "banana" ); break;
case 4:
System.out.println( "pear" ); case 5:
System.out.println( "grapes" ); default:
System.out.println( "kiwi" );
}
a) 2
b) any value equal to or greater than 4
c) 1
d) 3
Question 13. Consider the following segment of code.
if ( sex == 1 )
{ if ( age >= 65 )
++seniorFemales;
} // end if
Which of the following is equivalent to the segment of code above?
a) if ( sexe == 1 || age >= 65 ) ++seniorFemales;
b) if ( sexe == 1 && age >= 65 ) ++seniorFemales;
c) if ( sexe == 1 AND age >= 65 ) ++seniorFemales;
d) if ( sexe == 1 OR age >= 65 ) ++seniorFemales;
Question 14. Which of the following statements will compile without an error? Assume that the method is called upon using the following instruction and that the application contains only one getNumber method.
int num = getNumber(1,10);
a) 1
b) 2
c) 3
d) 4
Question 15. The following bloc of code is part of a more complex application. What will be the result of the following bloc of code?
public class Test
{
public void add (int b)
{
int Nums [ ] = new int [6]; for(int a=0; a < 7; a++)
{
Nums[a] = a*2; System.out.print(Nums[a]);
}
}
}
a) 0 2 4 6 8
b) 0 2 4 6 8 10 12
c) 0 2 4 6 8 16 32 64
d) An arrayIndexOutofBound exception is generated
Question 16. In the following Java instruction:
int Nombres[ ] = {5,10, 15, 20, 25};
Which of the following definition of method will be executed in response to a ModifierNumbers(Number[4]) instruction;?
a) public void ModifyNumbers(void)
b) public void ModifyNumbers(int b[ ] )
c) public void ModifyNumbers(int b)
d) public void ModifyNumbers(int b[4])
Question 17. The application on which you are working requires a randomly generated four digit number that will serve to identify the user. You decide to implement a method that will return the four digit ID. The call that activates this method is the following:
String UserID = getID(10);
Which of the following methods will return the ID as required?
a) 1
b) 2
c) 3
d) 4
Question 18. Which of the following statements about Break is false?
a) Break allows you to qui a loop structure prematurely and continue the execution after the loop
b) A break command allows you to quit immediately a while, for, do...while or switch structure in which we find the break.
c) The break command, when executed in a while, for or do...while structure, does not execute the commands that follow it and returns to the start of the structure to continue with a new iteration of the loop.
d) The common use of the break command is to quit a loop immediately and before its end, as well as to exit a switch structure.
Question 19. What will be the final value of c after the execution of the following segment of code?
int c = 8; c++;
++c;
c %= 5;
a) 0
b) 1
c) 3
d) None of these answers
Question 20. Considering that the file entitled Cercle.java contains the java code for a java application, the execution of this application will always start on the line of code.
a) static void main(String args[ ])
b) import java.*;
c) public class Cercle {
d) Cercle C = new Cercle( );
Question 21. What is a package?
a) A big package !
b) An object.
c) A list of folder and subfolders containing Java classes.
d) A list of java classes containing subfolders.
Question 22. Find the mistake in the following code
1 Scanner sc = new Scanner(System.in);
2 System.out.println("Please input an integer : ");
3 double d = sc.nextInt();
4 System.out.println("You have inserted the number : " + d);
a) No errors, the code will execute normally
b) We use nextInt() instead of nextDouble().
c) There is a ; missing somewhere
d) The use of new is not necessary to define sc.
Question 23. What must you never forget to do when you use a class that does not belong to the java.lang package?
a) Nothing at all as the necessary classes will be automatically added to the compilation of the program
b) To import the necessary class(es)
c) To configure the eclipse development environment or any other.
d) To add comments to the program
Question 24. The following question is based on this segement of code: public class afficherText
{
public static void main ( String args[ ] )
{
System.out.print("Welcome "); System.out.print("to the "); System.out.println("conference center. Please"); System.out.println("register at the reception.");
}
}
After the compilation and execution of this application, what will be the result produced by this segment of code?
1)
Welcome
Conference center. Please Register at the reception.
|
3)
Welcome to the conference center. Please register at the reception.
|
2)
|
4)
|
Welcome to the conference center. Please
|
Welcome to the conference
|
Register at the reception
|
Center. Please register
|
|
At the reception.
|
a) 1
b) 2
c) 3
d) 4
Question 25. A static type variable is:
a) a "class variable ". If the instance variable of this class is modified, all of the object instances are automatically modified. Therefore, the variable does not depend of the currant instance, but of the class.
b) a variable must be defined in every class instance
c) is used only in main(String args[ ])
d) is accessible only by methods that are declared static
Attachment:- Object Oriented Concepts.rar