advanced 40qstns nd ans

11
Question 1 1. What does the following UML diagram entry mean? + setHeight(h : double) : void this is a private attribute named Height and is a double data type this is a public method with a parameter of data type double and does not return a value this is a public attribute named Height and is a double data type this is a private method with no parameters and returns a double data type 0.25 points Question 2 1. Look at the following statement. import java.util.*; This is an example of: unconditional import conditional im port an explicit import a wildcard import 0.25 points Question 3 1. In the following code, System.out.println(num) is an example of: double num = 5.4; System.out.println(num); num = 0.0; a complex method a local variable a value- returning method

Upload: ranga-reddy

Post on 05-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced 40Qstns Nd Ans

Question 11. What does the following UML diagram entry mean?

+ setHeight(h : double) : void

this is a private attribute named Height and is a double data type

this is a public method with a parameter of data type double and does not return a valuethis is a public attribute named Height and is a double data type

this is a private method with no parameters and returns a double data type

0.25 points    

Question 21. Look at the following statement.

import java.util.*;

This is an example of:unconditional import

conditional import

an explicit import

a wildcard import

0.25 points    

Question 31. In the following code, System.out.println(num) is an example of:

double num = 5.4;System.out.println(num);num = 0.0;

a complex method

a local variable

a value-returning methoda void method

0.25 points    

Question 41. If method A calls method B, and method B calls method C, and method C

calls method D, when method D finishes, what happens?

Control is returned to method A.Control is returned to

Page 2: Advanced 40Qstns Nd Ans

method B.Control is returned to method C.The program terminates.

0.25 points    

Question 51. Given the following code, what will be the value of finalAmount when it is

displayed?

528.00

580.00

There is no value because the constructor has an error.There is no value because the object order has not been created.

0.25 points    

Question 61. Any method that calls a method with a throws clause in its header must either

handle the potential exception or have the same throws clause.

 True

 False

0.25 points    

Question 71. What will be the result of the following code?

int num;string str = "555";num = Integer.parseInt(string str) + 5;

str will have a value of "560".

The last line of code will cause an error.num will be set to 560.

Neither num or str will be changed.

0.25 points    

Question 81. An access specifier indicates how the class may be accessed.

 True

Page 3: Advanced 40Qstns Nd Ans

 False

0.25 points    

Question 91. The do-while loop must be terminated with a semicolon.

 True

 False

0.25 points    

Question 101. The scope of a public instance field is:

inside the parentheses of a method headerinside the class, but not inside any methodthe instance methods and methods outside the classonly the class in which it is defined

0.25 points    

Question 111. In UML diagrams, this symbol indicates that a member is private:

#

-

+

*

0.25 points    

Question 121. In the following code, what values could be read into number to terminate

the while loop?

Numbers in the range 100 - 499

Numbers in the range 100 - 500

Numbers less than 100 or greater than 500The boolean condition can never be true.

0.25 points    

Page 4: Advanced 40Qstns Nd Ans

Question 131. Java allows you to create objects of this class in the same way you would

create primitive variables.Random

PrintWriter

Scanner

String

0.25 points    

Question 141. The lifetime of a method's local variable is:

the duration of the method that called the local variable's methodonly while the method is executing

the duration of the class to which the method belongsthe duration of the program

0.25 points    

Question 151. A constructor is a method that is automatically called when an object is

created.

 True

 False

0.25 points    

Question 161. This type of loop will always be executed at least once.

pre-test looppost-test loopfor loop

sentinel loop

0.25 points    

Question 171. Class objects normally have ________ that perform useful operations on their

data, but primitive variables do not.

instances

Page 5: Advanced 40Qstns Nd Ans

fields

relationshipsmethods

0.25 points    

Question 181. A sentinel value ________ and signals that there are no more values to be

entered.

indicates the start of a list

guards the list

is a special value that cannot be mistaken as a member of the listis a different data type than the values being processed

0.25 points    

Question 191. A file must always be opened before using it and closed when the program is

finished using it.

 True

 False

0.25 points    

Question 201. Constants, variables, and the values of expressions may be passed as

arguments to a method.

 True

 False

0.25 points    

Question 211. Overloading means multiple methods in the same class:

have the same name, but different return typeshave different names, but the same parameter listhave the same name, but different parameter listsperform the same function

0.25 points    

Page 6: Advanced 40Qstns Nd Ans

Question 221. A value-returning method can return a reference to a non-primitive type.

 True

 False

0.25 points    

Question 231. This part of a method is a collection of statements that are performed when

the method is executed.

return type

method modifiermethod headermethod body

0.25 points    

Question 241. This type of loop is ideal in situations where the exact number of iterations is

known.

if statementdo-while loopwhile loop

for loop

0.25 points    

Question 251. Given the following method header, which of the method calls would be an

error?

public void displayValues(int x, int y)

displayValue(a,b); // where a is a short and b is a bytedisplayValue(a,b); // where a is an int and b is a bytedisplayValue(a,b); // where a is a short and b is a longThey would all give an error.

0.25 points    

Question 26

Page 7: Advanced 40Qstns Nd Ans

1. Given the following statement, which statement will write "Calvin" to the file DiskFile.txt?

PrintWriter diskOut = new PrintWriter("DiskFile.txt");diskOut.println("Calvin");

DiskFile.println("Calvin");

PrintWriter.println("Calvin");

System.out.println(diskOut, "Calvin");

0.25 points    

Question 271. How many times will the following do-while loop be executed?

1

3

4

5

0.25 points    

Question 281. All @param tags in a method's documentation comment must:

end with a */

span several lines

appear before the method header

appear after the general description of the method

0.25 points    

Question 291. A method that gets a value from a class's field but does not change it is

known as a mutator method.

 True

 False

0.25 points    

Question 301. Each repetition of a loop is known as what?

A cycle

An

Page 8: Advanced 40Qstns Nd Ans

iterationAn executionA Lap

0.25 points    

Question 311. What will be returned from the following method?

18.0

18 (as an integer)8

This is an error.

0.25 points    

Question 321. The following package is automatically imported into all Java programs.

java.default

java.java

java.lang

java.util

0.25 points    

Question 331. In a UML diagram to indicate the data type of a variable enter:

the variable name followed by the data type

the variable name followed by a colon and the data type

the class name followed by the variable name followed by the data typethe data type followed by the variable name

0.25 points    

Question 341. To create a method you must write its:

body

return type

Page 9: Advanced 40Qstns Nd Ans

definitionheader

0.25 points    

Question 351. A parameter variable's scope is the method in which the parameter is

declared.

 True

 False

0.25 points    

Question 361. When you open a file with the PrintWriter class, the class can potentially

throw an IOException.

 True

 False

0.25 points    

Question 371. This is a control structure that causes a statement or group of statements to

repeat.

Prefix modeBody

Loop

Block

0.25 points    

Question 381. A class specifies the ________ and ________ that a particular type of object

has.

relationships; object namesrelationships; methodsfields; object names

fields; methods

0.25 points    

Question 39

Page 10: Advanced 40Qstns Nd Ans

1. The term "default constructor" is applied to the first constructor written by the author of a class.

 True

 False

0.25 points    

Question 401. A UML diagram does not contain:

object names

the class namethe method namesthe field names