Deck 6: Methods: a Deeper Look
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/42
العب
ملء الشاشة (f)
Deck 6: Methods: a Deeper Look
1
Programs designed for maintainability are constructed from small simple pieces or modules.Modules in Java are called:
A)methods.
B)classes.
C)arguments.
D)both methods and classes.
A)methods.
B)classes.
C)arguments.
D)both methods and classes.
D
2
Which of the following can be an argument to a method?
A)Constants.
B)Variables.
C)Expressions.
D)All of the above.
A)Constants.
B)Variables.
C)Expressions.
D)All of the above.
D
3
Which statement is false?
A)If a method does not return a value,the return-value-type in the method declaration can be omitted.
B)Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.
C)Redeclaring a method parameter as a local variable in the method's body is a compilation error.
D)Forgetting to return a value from a method that should return a value is a compilation error.
A)If a method does not return a value,the return-value-type in the method declaration can be omitted.
B)Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.
C)Redeclaring a method parameter as a local variable in the method's body is a compilation error.
D)Forgetting to return a value from a method that should return a value is a compilation error.
A
4
Information is passed to a method in:
A)the method name.
B)that method's return.
C)the method body.
D)the arguments to the method.
A)the method name.
B)that method's return.
C)the method body.
D)the arguments to the method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
5
Method log takes the logarithm of its argument with respect to what base?
A)10
B)e
C)2
D)pi
A)10
B)e
C)2
D)pi
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
6
Consider the following Java statements: int x = 9;
Double y = 5.3;
Result = calculateValue( x,y );
Which of the following statements is false?
A)A method is called with its name and parentheses.
B)x and y are parameters.
C)Copies of x and y are passed to the method calculateValue.
D)x and y are arguments.
Double y = 5.3;
Result = calculateValue( x,y );
Which of the following statements is false?
A)A method is called with its name and parentheses.
B)x and y are parameters.
C)Copies of x and y are passed to the method calculateValue.
D)x and y are arguments.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
7
A static method can ________.
A)call only other static methods of the same class directly.
B)manipulate only static fields in the same class directly.
C)be called using the class name and a dot (. ).
D)All of the above.
A)call only other static methods of the same class directly.
B)manipulate only static fields in the same class directly.
C)be called using the class name and a dot (. ).
D)All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
8
A well-designed method
A)performs multiple unrelated tasks.
B)repeats code found in other methods.
C)contains thousands of lines of code.
D)performs a single,well-defined task.
A)performs multiple unrelated tasks.
B)repeats code found in other methods.
C)contains thousands of lines of code.
D)performs a single,well-defined task.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
9
Variables should be declared as fields only if
A)they are local variables.
B)they are used only within a method.
C)they are required for use in more than one method or their values must be saved between calls to the class's methods.
D)they are arguments.
A)they are local variables.
B)they are used only within a method.
C)they are required for use in more than one method or their values must be saved between calls to the class's methods.
D)they are arguments.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following promotions of primitive types is not allowed to occur?
A)char to int.
B)int to double.
C)short to long.
D)double to float.
A)char to int.
B)int to double.
C)short to long.
D)double to float.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
11
If more method calls occur than can have their activation records stored on the program execution stack,an error known as a ________ occurs.
A)stack overflow.
B)stack rewind.
C)stack full.
D)stack empty.
A)stack overflow.
B)stack rewind.
C)stack full.
D)stack empty.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
12
Any field declared with keyword ________ is constant.
A)static.
B)const.
C)constant.
D)final.
A)static.
B)const.
C)constant.
D)final.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
13
When an object is concatenated with a String:
A)a compilation error occurs.
B)a runtime error occurs.
C)the object's toString method is implicitly called to obtain the String representation of the object.
D)the object's class name is used.
A)a compilation error occurs.
B)a runtime error occurs.
C)the object's toString method is implicitly called to obtain the String representation of the object.
D)the object's class name is used.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
14
Which operator can be used in string concatenation?
A)*.
B)+=.
C)++.
D)=+.
A)*.
B)+=.
C)++.
D)=+.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
15
The parameter list in the method header and the arguments in the method call must agree in:
A)number
B)type
C)order
D)all of the above
A)number
B)type
C)order
D)all of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
16
To declare a method as static,place the keyword static before ________ in the method's declaration.
A)the method modifier.
B)the return type.
C)the method name.
D)the argument list.
A)the method modifier.
B)the return type.
C)the method name.
D)the argument list.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
17
Declaring main as ________ allows the JVM to invoke main without creating an instance of the class.
A)public.
B)void.
C)static.
D)final.
A)public.
B)void.
C)static.
D)final.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
18
Stacks are known as ________ data structures.
A)FIFO.
B)FILO.
C)LIFO.
D)LILO.
A)FIFO.
B)FILO.
C)LIFO.
D)LILO.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
19
Which is a correct static method call of Math class method sqrt?
A)sqrt( 900 );.
B)math.sqrt( 900 );.
C)Math.sqrt( 900 );.
D)Math math = new Math();math.sqrt( 900 );.
A)sqrt( 900 );.
B)math.sqrt( 900 );.
C)Math.sqrt( 900 );.
D)Math math = new Math();math.sqrt( 900 );.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
20
Which of the following methods is not in the Math class?
A)ceil.
B)abs.
C)parseInt.
D)log.
A)ceil.
B)abs.
C)parseInt.
D)log.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
21
Math static method random generates a random double value in the range from 0.0
A)up to but not including 1.0
B)up to and including 1.0
C)up to and including 100.0
D)up to but not including 100.0
A)up to but not including 1.0
B)up to and including 1.0
C)up to and including 100.0
D)up to but not including 100.0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
22
An enumeration is a special class that's introduced by the keyword ________ and a type name.
A)class.
B)enum.
C)enumeration.
D)classEnum.
A)class.
B)enum.
C)enumeration.
D)classEnum.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
23
The java.text package contains classes for manipulating all of the following items except
A)classes
B)numbers
C)strings
D)characters
A)classes
B)numbers
C)strings
D)characters
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
24
You can set a Random object's seed at any time during program execution by calling the object's ________ methods.
A)changeSeed.
B)setSeed.
C)resetSeed.
D)updateSeed.
A)changeSeed.
B)setSeed.
C)resetSeed.
D)updateSeed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
25
Overloaded methods always have the same _________.
A)method name.
B)return type.
C)number of parameters.
D)order of the parameters.
A)method name.
B)return type.
C)number of parameters.
D)order of the parameters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
26
Which statement below could be used to simulate the outputs of rolling a six-sided die? Suppose randomNumbers is a Random object.
A)1 + randomNumbers.nextInt( 6 );
B)1 + randomNumbers.nextInt( 2 );
C)6 + randomNumbers.nextInt( 1 );
D)3 + randomNumbers.nextInt( 3 );
A)1 + randomNumbers.nextInt( 6 );
B)1 + randomNumbers.nextInt( 2 );
C)6 + randomNumbers.nextInt( 1 );
D)3 + randomNumbers.nextInt( 3 );
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
27
Which statement below could be used to simulate the outputs of tossing a quarter to get heads or tails? Suppose randomNumbers is a Random object.
A)randomNumbers.nextInt( 7 );
B)randomNumbers.nextInt( 2 );
C)randomNumbers.nextInt( 1 );
D)randomNumbers.nextInt( 25 );
A)randomNumbers.nextInt( 7 );
B)randomNumbers.nextInt( 2 );
C)randomNumbers.nextInt( 1 );
D)randomNumbers.nextInt( 25 );
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
28
Method calls cannot be distinguished by ________.
A)method name.
B)return type.
C)parameter lists.
D)method signature.
A)method name.
B)return type.
C)parameter lists.
D)method signature.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
29
Identifiers in Java have ________ and ________ scopes?
A)method,class.
B)class,block.
C)block,statement.
D)statement,file.
A)method,class.
B)class,block.
C)block,statement.
D)statement,file.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
30
Suppose method1 is declared as void method1 ( int a,float b )
Which of the following methods correctly overloads method1?
A)void method2 ( int a,float b ).
B)void method2 ( float a,int b ).
C)void method1 ( float a,int b ).
D)void method1 ( int b,float a ).
Which of the following methods correctly overloads method1?
A)void method2 ( int a,float b ).
B)void method2 ( float a,int b ).
C)void method1 ( float a,int b ).
D)void method1 ( int b,float a ).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which of the following methods are overloaded with respect to one another? public int max ( int a,int b ){ … }
Public double max ( double a,double b ){ … }
Public int max ( int a,int b,int c ){ … }
Public double max ( double a,double b,double c ){ … }
A)A and B are overloaded;C and D are overloaded.
B)A and C are overloaded;B and D are overloaded.
C)A,B and C are overloaded.
D)All these four methods are overloaded.
Public double max ( double a,double b ){ … }
Public int max ( int a,int b,int c ){ … }
Public double max ( double a,double b,double c ){ … }
A)A and B are overloaded;C and D are overloaded.
B)A and C are overloaded;B and D are overloaded.
C)A,B and C are overloaded.
D)All these four methods are overloaded.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
32
Which of the following is not a package in the Java API?
A)java.component.
B)java.awt.
C)javax.swing.event.
D)java.lang.
A)java.component.
B)java.awt.
C)javax.swing.event.
D)java.lang.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
33
An overloaded method is one that
A)has a different name than another method,but the same parameters.
B)has the same name as another method,but different parameters (by number,types or order of the types).
C)has the same name and parameters as a method defined in another class.
D)has the same name and parameters,but a different return type as another method.
A)has a different name than another method,but the same parameters.
B)has the same name as another method,but different parameters (by number,types or order of the types).
C)has the same name and parameters as a method defined in another class.
D)has the same name and parameters,but a different return type as another method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which statement is not true.
A)The Java API consists of packages.
B)The Java API helps programmers avoid "reinventing the wheel."
C)The Java API consists of import declarations.
D)The class javax.swing.JApplet is part of the Java API.
A)The Java API consists of packages.
B)The Java API helps programmers avoid "reinventing the wheel."
C)The Java API consists of import declarations.
D)The class javax.swing.JApplet is part of the Java API.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
35
A Java class can have which of the following methods? A.void foo( int a )
B)void foo( int a,int b )
C)void foo( double a )
D)void foo( double a,double b )
E)void foo( int b )
A)All of the above.
B)A,B,D,E.
C)A,B,C,D.
D)A,C,D,E.
B)void foo( int a,int b )
C)void foo( double a )
D)void foo( double a,double b )
E)void foo( int b )
A)All of the above.
B)A,B,D,E.
C)A,B,C,D.
D)A,C,D,E.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
36
Which statement creates a random value from the sequence 2,5,8,11 and 14.Suppose randomNumbers is a Random object.
A)2 + 5 * randomNumbers.nextInt( 3 );
B)3 + 2 * randomNumbers.nextInt( 5 );
C)5 + 3 * randomNumbers.nextInt( 2 );
D)2 + 3 * randomNumbers.nextInt( 5 );
A)2 + 5 * randomNumbers.nextInt( 3 );
B)3 + 2 * randomNumbers.nextInt( 5 );
C)5 + 3 * randomNumbers.nextInt( 2 );
D)2 + 3 * randomNumbers.nextInt( 5 );
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
37
In a class containing methods with the same name,the methods are distinguished by:
A)Number of arguments.
B)Types of arguments.
C)Return type.
D)(a)and (b).
E)(b)and (c).
A)Number of arguments.
B)Types of arguments.
C)Return type.
D)(a)and (b).
E)(b)and (c).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
38
Which of the following statements describes block scope?
A)It begins at the opening { of the class declaration and terminates at the closing }
B)It limits label scope to only the method in which it is declared.
C)It begins at the identifier's declaration and ends at the terminating right brace (}).
D)It is valid for one statement only.
A)It begins at the opening { of the class declaration and terminates at the closing }
B)It limits label scope to only the method in which it is declared.
C)It begins at the identifier's declaration and ends at the terminating right brace (}).
D)It is valid for one statement only.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
39
The identifiers in an enumeration ________.
A)must be unique.
B)may be duplicated.
C)must be lowercase letters and cannot contain numbers.
D)must be uppercase letters and cannot contain numbers.
A)must be unique.
B)may be duplicated.
C)must be lowercase letters and cannot contain numbers.
D)must be uppercase letters and cannot contain numbers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
40
Which of these statements best defines scope?
A)Scope refers to the classes that have access to a variable.
B)Scope determines whether a variable's value can be altered.
C)Scoping allows the programmer to use a class without using its fully qualified name.
D)Scope is the portion of a program that can refer to an entity by its simple name.
A)Scope refers to the classes that have access to a variable.
B)Scope determines whether a variable's value can be altered.
C)Scoping allows the programmer to use a class without using its fully qualified name.
D)Scope is the portion of a program that can refer to an entity by its simple name.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
41
Filled rectangles and filled circles are drawn using Graphics method ________ and ________.
A)fillRect,fillCircle.
B)filledRect,filledCircle.
C)fillRect,fillOval,
D)filledRect,filledOval.
A)fillRect,fillCircle.
B)filledRect,filledCircle.
C)fillRect,fillOval,
D)filledRect,filledOval.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
42
Java uses class ________ to represent colors using their RGB values.
A)Color.
B)Colors.
C)RGBColor.
D)RGBColors.
A)Color.
B)Colors.
C)RGBColor.
D)RGBColors.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck