Deck 8: Classes and Objects: a Deeper Look

ملء الشاشة (f)
exit full mode
سؤال
Which statement is false?

A)An enum declaration is a comma-separated list of enum constants and may optionally include other components of traditional classes,such as constructors,fields and methods.
B)Any attempt to create an object of an enum type with operator new results in a compilation error.
C)An enum constructor cannot be overloaded.
D)An enum constructor can specify any number of parameters.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Static class variables:

A)are final.
B)are public.
C)are private.
D)are shared by all objects of a class.
سؤال
Which statement is false?

A)The compiler always creates a default constructor for a class.
B)If a class's constructors all require arguments and a program attempts to call a no-argument constructor to initialize an object of the class,a compilation error occurs.
C)A constructor can be called with no arguments only if the class does not have any constructors or if the class has a public no-argument constructor.
D)None of the above.
سؤال
Which statement is false?

A)The actual data representation used within the class is of no concern to the class's clients.
B)Clients generally care about what the class does but not how the class does it.
C)Clients are usually involved in a class's implementation.
D)Hiding the implementation reduces the possibility that clients will become dependent on class-implementation details.
سؤال
Composition is sometimes referred to as a(n)________.

A)is-a relationship.
B)has-a relationship.
C)many-in-one relationship.
D)one-to-many relationship.
سؤال
Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods.

A)query,mutator.
B)accessor,mutator.
C)mutator,accessor.
D)query,accessor.
سؤال
When implementing a method,use the class's set and get methods to access the class's ________ data.

A)public.
B)private.
C)protected.
D)All of the above.
سؤال
Having a this reference allows:

A)a method to refer explicitly to the instance variables and other methods of the object on which the method was called.
B)a method to refer implicitly to the instance variables and other methods of the object on which the method was called.
C)an object to reference itself.
D)All of the above.
سؤال
The _________ of a class are also called the public services or the public interface that the class provides to its clients.

A)public constructors.
B)public instance variables.
C)public methods.
D)All of the above.
سؤال
Which method returns an array of the enum's constants?

A)values.
B)getValues.
C)constants.
D)getConstants.
سؤال
Which of the following is false?

A)A static method must be used to access private static instance variables.
B)A static method has no this reference.
C)A static method can be accessed even when no objects of its class have been instantiated.
D)A static method can call instance methods directly.
سؤال
Enum types are implicitly ________ and enum constants are implicitly ________.

A)final,static.
B)static,static.
C)static,final.
D)final,final.
سؤال
What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor?

A)A compilation error occurs.
B)A runtime error occurs.
C)A logic error occurs.
D)Nothing happens.The program compiles and runs.
سؤال
A programmer-defined constructor that has no arguments is called a(n)________.

A)empty constructor.
B)no-argument constructor.
C)default constructor.
D)null constructor.
سؤال
The static method ________ of class String returns a formatted String.

A)printf.
B)format.
C)formatString.
D)toFormatString.
سؤال
A constructor cannot:

A)be overloaded.
B)initialize variables to their defaults.
C)specify return types or return values.
D)have the same name as the class.
سؤال
Which of the following is false?

A)Method finalize does not take parameters and has return type void.
B)Memory leaks using Java are rare because of automatic garbage collection.
C)Objects are marked for garbage collection by method finalize.
D)The garbage collector reclaims unused memory.
سؤال
Which of the following statements is true?

A)Methods and instance variables can both be either public or private.
B)Information hiding is achieved by restricting access to class members via keyword public.
C)The private members of a class are directly accessible to the client of a class.
D)None of the above is true.
سؤال
Which of the following should usually be private?

A)Methods.
B)Constructors.
C)Variables (or fields).
D)All of the above.
سؤال
When should a program explicitly use the this reference?

A)Accessing a private variable.
B)Accessing a public variable.
C)Accessing a local variable.
D)Accessing a field that is shadowed by a local variable.
سؤال
Which syntax imports all static members of class Math?

A)static import java.lang.Math.*.
B)import static java.lang.Math.*.
C)static import java.lang.Math.
D)import static java.lang.Math.
سؤال
By default,the classpath consists only of the ________.However,the classpath can be modified by providing the ________ option to the javac compiler.

A)root directory of the package,-d.
B)current directory,-d.
C)root directory of the package,-classpath.
D)current directory,-classpath.
سؤال
When no access modifier is specified for a method or variable,the method or variable:

A)Is public.
B)Is private.
C)Has package access.
D)Is static.
سؤال
The import declaration import java.util.*;is known as a ________.

A)single-type-import declaration.
B)all-type-import declaration.
C)multiple-import declaration.
D)type-import-on-demand declaration.
سؤال
A final field should also be declared ________ if it is initialized in its declaration.

A)private.
B)public.
C)protected.
D)static.
سؤال
A package is:

A)A directory structure used to organize classes and interfaces.
B)A mechanism for software reuse.
C)A group of related classes and interfaces.
D)All of the above.
سؤال
A class within a package must be declared public if

A)It will be used only by other classes in the same package.
B)It will be used by classes that are not in the same package.
C)It is in the same directory as the other classes in the package.
D)It has a unique name.
سؤال
The import declaration import *;________.

A)causes a compilation error.
B)imports all classes in the library.
C)imports the default classes in the library.
D)imports the classes in package java.lang.
سؤال
The classpath consists of a list of directories or archive files,each separated by a ________ on Windows or a ________ on UNIX/Linux/Max OS X.

A)colon (:),semicolon (;).
B)semicolon (;),colon (:).
C)comma (,),semicolon (;).
D)semicolon (;),comma (,).
سؤال
Instance variables declared final do not or cannot:

A)Cause syntax errors if used as a left-hand value.
B)Be initialized.
C)Be modified.
D)None of the above.
سؤال
When compiling a class in a package,the javac command-line option ________ causes the javac compiler to create appropriate directories based on the class's package declaration.

A)-p.
B)-a.
C)-d.
D)-dir.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/31
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 8: Classes and Objects: a Deeper Look
1
Which statement is false?

A)An enum declaration is a comma-separated list of enum constants and may optionally include other components of traditional classes,such as constructors,fields and methods.
B)Any attempt to create an object of an enum type with operator new results in a compilation error.
C)An enum constructor cannot be overloaded.
D)An enum constructor can specify any number of parameters.
C
2
Static class variables:

A)are final.
B)are public.
C)are private.
D)are shared by all objects of a class.
D
3
Which statement is false?

A)The compiler always creates a default constructor for a class.
B)If a class's constructors all require arguments and a program attempts to call a no-argument constructor to initialize an object of the class,a compilation error occurs.
C)A constructor can be called with no arguments only if the class does not have any constructors or if the class has a public no-argument constructor.
D)None of the above.
A
4
Which statement is false?

A)The actual data representation used within the class is of no concern to the class's clients.
B)Clients generally care about what the class does but not how the class does it.
C)Clients are usually involved in a class's implementation.
D)Hiding the implementation reduces the possibility that clients will become dependent on class-implementation details.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
5
Composition is sometimes referred to as a(n)________.

A)is-a relationship.
B)has-a relationship.
C)many-in-one relationship.
D)one-to-many relationship.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
6
Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods.

A)query,mutator.
B)accessor,mutator.
C)mutator,accessor.
D)query,accessor.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
7
When implementing a method,use the class's set and get methods to access the class's ________ data.

A)public.
B)private.
C)protected.
D)All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
8
Having a this reference allows:

A)a method to refer explicitly to the instance variables and other methods of the object on which the method was called.
B)a method to refer implicitly to the instance variables and other methods of the object on which the method was called.
C)an object to reference itself.
D)All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
9
The _________ of a class are also called the public services or the public interface that the class provides to its clients.

A)public constructors.
B)public instance variables.
C)public methods.
D)All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which method returns an array of the enum's constants?

A)values.
B)getValues.
C)constants.
D)getConstants.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
11
Which of the following is false?

A)A static method must be used to access private static instance variables.
B)A static method has no this reference.
C)A static method can be accessed even when no objects of its class have been instantiated.
D)A static method can call instance methods directly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
12
Enum types are implicitly ________ and enum constants are implicitly ________.

A)final,static.
B)static,static.
C)static,final.
D)final,final.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
13
What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor?

A)A compilation error occurs.
B)A runtime error occurs.
C)A logic error occurs.
D)Nothing happens.The program compiles and runs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
14
A programmer-defined constructor that has no arguments is called a(n)________.

A)empty constructor.
B)no-argument constructor.
C)default constructor.
D)null constructor.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
15
The static method ________ of class String returns a formatted String.

A)printf.
B)format.
C)formatString.
D)toFormatString.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
16
A constructor cannot:

A)be overloaded.
B)initialize variables to their defaults.
C)specify return types or return values.
D)have the same name as the class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which of the following is false?

A)Method finalize does not take parameters and has return type void.
B)Memory leaks using Java are rare because of automatic garbage collection.
C)Objects are marked for garbage collection by method finalize.
D)The garbage collector reclaims unused memory.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
18
Which of the following statements is true?

A)Methods and instance variables can both be either public or private.
B)Information hiding is achieved by restricting access to class members via keyword public.
C)The private members of a class are directly accessible to the client of a class.
D)None of the above is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
19
Which of the following should usually be private?

A)Methods.
B)Constructors.
C)Variables (or fields).
D)All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
20
When should a program explicitly use the this reference?

A)Accessing a private variable.
B)Accessing a public variable.
C)Accessing a local variable.
D)Accessing a field that is shadowed by a local variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which syntax imports all static members of class Math?

A)static import java.lang.Math.*.
B)import static java.lang.Math.*.
C)static import java.lang.Math.
D)import static java.lang.Math.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
22
By default,the classpath consists only of the ________.However,the classpath can be modified by providing the ________ option to the javac compiler.

A)root directory of the package,-d.
B)current directory,-d.
C)root directory of the package,-classpath.
D)current directory,-classpath.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
23
When no access modifier is specified for a method or variable,the method or variable:

A)Is public.
B)Is private.
C)Has package access.
D)Is static.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
24
The import declaration import java.util.*;is known as a ________.

A)single-type-import declaration.
B)all-type-import declaration.
C)multiple-import declaration.
D)type-import-on-demand declaration.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
25
A final field should also be declared ________ if it is initialized in its declaration.

A)private.
B)public.
C)protected.
D)static.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
26
A package is:

A)A directory structure used to organize classes and interfaces.
B)A mechanism for software reuse.
C)A group of related classes and interfaces.
D)All of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
27
A class within a package must be declared public if

A)It will be used only by other classes in the same package.
B)It will be used by classes that are not in the same package.
C)It is in the same directory as the other classes in the package.
D)It has a unique name.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
28
The import declaration import *;________.

A)causes a compilation error.
B)imports all classes in the library.
C)imports the default classes in the library.
D)imports the classes in package java.lang.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
29
The classpath consists of a list of directories or archive files,each separated by a ________ on Windows or a ________ on UNIX/Linux/Max OS X.

A)colon (:),semicolon (;).
B)semicolon (;),colon (:).
C)comma (,),semicolon (;).
D)semicolon (;),comma (,).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
30
Instance variables declared final do not or cannot:

A)Cause syntax errors if used as a left-hand value.
B)Be initialized.
C)Be modified.
D)None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
31
When compiling a class in a package,the javac command-line option ________ causes the javac compiler to create appropriate directories based on the class's package declaration.

A)-p.
B)-a.
C)-d.
D)-dir.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 31 في هذه المجموعة.