Deck 6: A First Look at Classes
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/58
العب
ملء الشاشة (f)
Deck 6: A First Look at Classes
1
In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.
A) object; classes
B) class; objects
C) class; fields
D) attribute; methods
A) object; classes
B) class; objects
C) class; fields
D) attribute; methods
B
2
Most programming languages that are in use today are:
A) procedural
B) logic
C) object-oriented
D) functional
A) procedural
B) logic
C) object-oriented
D) functional
C
3
Which of the following statements will create a reference, str, to the String, "Hello, World"?
A) String str = "Hello, World";
B) string str = "Hello, World";
C) String str = new "Hello, World";
D) str = "Hello, World";
A) String str = "Hello, World";
B) string str = "Hello, World";
C) String str = new "Hello, World";
D) str = "Hello, World";
A
4
Java allows you to create objects of this class in the same way you would create primitive variables.
A) Random
B) String
C) PrintWriter
D) Scanner
A) Random
B) String
C) PrintWriter
D) Scanner
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
5
Given the following code, what will be the value of finalAmount when it is displayed?
Public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public int getOrderAmount()
{
Return orderAmount;
}
Public int getOrderDisc()
{
Return orderDisc;
}
}
Public class CustomerOrder
{
Public static void main(String[] args)
{
Int ordNum = 1234;
Double ordAmount = 580.00;
Double discountPer = .1;
Order order;
Double finalAmount = order.getOrderAmount() -
Order.getOrderAmount() * order.getOrderDisc();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) There is no value because the constructor has an error.
D) There is no value because the object order has not been created.
Public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public int getOrderAmount()
{
Return orderAmount;
}
Public int getOrderDisc()
{
Return orderDisc;
}
}
Public class CustomerOrder
{
Public static void main(String[] args)
{
Int ordNum = 1234;
Double ordAmount = 580.00;
Double discountPer = .1;
Order order;
Double finalAmount = order.getOrderAmount() -
Order.getOrderAmount() * order.getOrderDisc();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) There is no value because the constructor has an error.
D) There is no value because the object order has not been created.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
6
For the following code, which statement is NOT true?
Public class Sphere
{
Private double radius;
Public double x;
Private double y;
Private double z;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius, x, y, and z are called members of the Circle class.
D) z is available to code that is written outside the Circle class.
Public class Sphere
{
Private double radius;
Public double x;
Private double y;
Private double z;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius, x, y, and z are called members of the Circle class.
D) z is available to code that is written outside the Circle class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which of the following are classes from the Java API?
A) Scanner
B) Random
C) PrintWriter
D) All of the above
A) Scanner
B) Random
C) PrintWriter
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
8
You should not define a class field that is dependent upon the values of other class fields:
A) in order to avoid having stale data
B) because it is redundant
C) because it should be defined in another class
D) in order to keep it current
A) in order to avoid having stale data
B) because it is redundant
C) because it should be defined in another class
D) in order to keep it current
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
9
When you are working with a ________, you are using a storage location that holds a piece of data.
A) primitive variable
B) reference variable
C) numeric literal
D) binary number
A) primitive variable
B) reference variable
C) numeric literal
D) binary number
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
10
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
A) fields
B) instances
C) methods
D) relationships
A) fields
B) instances
C) methods
D) relationships
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
11
What is stored by a reference variable?
A) A binary encoded decimal
B) A memory address
C) An object
D) A string
A) A binary encoded decimal
B) A memory address
C) An object
D) A string
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
12
One or more objects may be created from a(n):
A) field
B) class
C) method
D) instance
A) field
B) class
C) method
D) instance
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
13
Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by:
A) using the public access specifier on the class methods
B) using the private access specifier on the class methods
C) using the private access specifier on the class definition
D) using the private access specifier on the class fields
A) using the public access specifier on the class methods
B) using the private access specifier on the class methods
C) using the private access specifier on the class definition
D) using the private access specifier on the class fields
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
14
The scope of a private instance field is:
A) the instance methods of the same class
B) inside the class, but not inside any method
C) inside the parentheses of a method header
D) the method in which they are defined
A) the instance methods of the same class
B) inside the class, but not inside any method
C) inside the parentheses of a method header
D) the method in which they are defined
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
15
A class specifies the ________ and ________ that a particular type of object has.
A) relationships; methods
B) fields; object names
C) fields; methods
D) relationships; object names
A) relationships; methods
B) fields; object names
C) fields; methods
D) relationships; object names
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
16
Two or more methods in a class may have the same name as long as:
A) they have different return types
B) they have different parameter lists
C) they have different return types, but the same parameter list
D) you cannot have two methods with the same name
A) they have different return types
B) they have different parameter lists
C) they have different return types, but the same parameter list
D) you cannot have two methods with the same name
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
17
A constructor:
A) always accepts two arguments
B) has return type of void
C) has the same name as the class
D) always has an access specifier of private
A) always accepts two arguments
B) has return type of void
C) has the same name as the class
D) always has an access specifier of private
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
18
What does the following UML diagram entry mean?
+ setHeight(h : double) : void
A) this is a public attribute named Height and is a double data type
B) this is a private method with no parameters and returns a double data type
C) this is a private attribute named Height and is a double data type
D) this is a public method with a parameter of data type double and does not return a value
+ setHeight(h : double) : void
A) this is a public attribute named Height and is a double data type
B) this is a private method with no parameters and returns a double data type
C) this is a private attribute named Height and is a double data type
D) this is a public method with a parameter of data type double and does not return a value
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
19
Methods that operate on an object's fields are called:
A) instance variables
B) instance methods
C) public methods
D) private methods
A) instance variables
B) instance methods
C) public methods
D) private methods
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
20
A UML diagram does not contain:
A) the class name
B) the method names
C) the field names
D) object names
A) the class name
B) the method names
C) the field names
D) object names
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
21
This is a group of related classes.
A) archive
B) package
C) collection
D) attachment
A) archive
B) package
C) collection
D) attachment
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
22
In UML diagrams, this symbol indicates that a member is private:
A) *
B) #
C) -
D) +
A) *
B) #
C) -
D) +
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
23
When an object is created, the attributes associated with the object are called:
A) instance fields
B) instance methods
C) fixed attributes
D) class instances
A) instance fields
B) instance methods
C) fixed attributes
D) class instances
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
24
Another term for an object of a class is:
A) access specifier
B) instance
C) member
D) method
A) access specifier
B) instance
C) member
D) method
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
25
In UML diagrams, this symbol indicates that a member is public.
A) /
B) @
C) -
D) +
A) /
B) @
C) -
D) +
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
26
In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the ________; the middle section holds ________; the bottom section holds ________.
A) class name; attributes or fields; methods
B) class name; object name; methods
C) object name; attributes or fields; methods
D) object name; methods; attributes or fields
A) class name; attributes or fields; methods
B) class name; object name; methods
C) object name; attributes or fields; methods
D) object name; methods; attributes or fields
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
27
Which of the following is NOT involved in finding the classes when developing an object-oriented application?
A) Describe the problem domain.
B) Identify all the nouns.
C) Write the code.
D) Refine the list of nouns to include only those that are relevant to the problem.
A) Describe the problem domain.
B) Identify all the nouns.
C) Write the code.
D) Refine the list of nouns to include only those that are relevant to the problem.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
28
For the following code, which statement is NOT true?
Public class Circle
{
Private double radius;
Public double x;
Private double y;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius, x, and y are called members of the Circle class.
D) y is available to code that is written outside the Circle class.
Public class Circle
{
Private double radius;
Public double x;
Private double y;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius, x, and y are called members of the Circle class.
D) y is available to code that is written outside the Circle class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
29
A constructor is a method that:
A) returns an object of the class.
B) never receives any arguments.
C) with the name ClassName.constructor.
D) performs initialization or setup operations.
A) returns an object of the class.
B) never receives any arguments.
C) with the name ClassName.constructor.
D) performs initialization or setup operations.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
30
Instance methods do not have this key word in their headers:
A) public
B) static
C) private
D) protected
A) public
B) static
C) private
D) protected
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
31
Overloading means multiple methods in the same class:
A) have the same name, but different return types
B) have different names, but the same parameter list
C) have the same name, but different parameter lists
D) perform the same function
A) have the same name, but different return types
B) have different names, but the same parameter list
C) have the same name, but different parameter lists
D) perform the same function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
32
The scope of a public instance field is:
A) only the class in which it is defined
B) inside the class, but not inside any method
C) inside the parentheses of a method header
D) the instance methods and methods outside the class
A) only the class in which it is defined
B) inside the class, but not inside any method
C) inside the parentheses of a method header
D) the instance methods and methods outside the class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which of the following statements will create a reference, str, to the string, "Hello, world"?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
A) 1
B) 2
C) 1 and 2
D) neither 1 or 2
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
A) 1
B) 2
C) 1 and 2
D) neither 1 or 2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
34
After the header, the body of the method appears inside a set of:
A) brackets, []
B) parentheses, ()
C) braces, {}
D) double quotes, ""
A) brackets, []
B) parentheses, ()
C) braces, {}
D) double quotes, ""
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
35
In a UML diagram to indicate the data type of a variable enter:
A) the variable name followed by the data type
B) the variable name followed by a colon and the data type
C) the class name followed by the variable name followed by the data type
D) the data type followed by the variable name
A) the variable name followed by the data type
B) the variable name followed by a colon and the data type
C) the class name followed by the variable name followed by the data type
D) the data type followed by the variable name
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
36
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
A) the class name
B) the object's memory address
C) the values for each field
D) the method names
A) the class name
B) the object's memory address
C) the values for each field
D) the method names
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
37
Given the following code, what will be the value of finalAmount when it is displayed?
Public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public double finalOrderTotal()
{
Return orderAmount - orderAmount *
OrderDiscount;
}
}
Public class CustomerOrder
{
Public static void main(String[] args)
{
Order order;
Int orderNumber = 1234;
Double orderAmt = 580.00;
Double orderDisc = .1;
Order = new Order(orderNumber, orderAmt, orderDisc);
Double finalAmount = order.finalOrderTotal();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) 522.00
D) There is no value because the object order has not been created.
Public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public double finalOrderTotal()
{
Return orderAmount - orderAmount *
OrderDiscount;
}
}
Public class CustomerOrder
{
Public static void main(String[] args)
{
Order order;
Int orderNumber = 1234;
Double orderAmt = 580.00;
Double orderDisc = .1;
Order = new Order(orderNumber, orderAmt, orderDisc);
Double finalAmount = order.finalOrderTotal();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) 522.00
D) There is no value because the object order has not been created.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
38
This refers to the combining of data and code into a single object.
A) Data hiding
B) Abstraction
C) Object
D) Encapsulation
A) Data hiding
B) Abstraction
C) Object
D) Encapsulation
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
39
It is common practice in object-oriented programming to make all of a class's:
A) methods private
B) fields private
C) fields public
D) fields and methods public
A) methods private
B) fields private
C) fields public
D) fields and methods public
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
40
A class's responsibilities include:
A) the things a class is responsible for doing
B) the things a class is responsible for knowing
C) both A and B
D) neither A nor B
A) the things a class is responsible for doing
B) the things a class is responsible for knowing
C) both A and B
D) neither A nor B
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
41
Look at the following statement. import java.util.Scanner;
This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
42
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
43
The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
44
A constructor is a method that is automatically called when an object is created.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
45
Instance methods do not have the key word static in their headers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
46
An access specifier indicates how the class may be accessed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
47
Quite often you have to use this statement to make a group of classes available to a program.
A) import
B) use
C) link
D) assume
A) import
B) use
C) link
D) assume
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
48
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
49
A class in not an object, but a description of an object.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
50
The java.lang package is automatically imported into all Java programs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
51
A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
52
An object can store data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
53
The following package is automatically imported into all Java programs.
A) java.java
B) java.default
C) java.util
D) java.lang
A) java.java
B) java.default
C) java.util
D) java.lang
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
54
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
55
The term "default constructor" is applied to the first constructor written by the author of a class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
56
Instance methods should be declared static.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
57
Look at the following statement. import java.util.*;
This is an example of:
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
This is an example of:
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck
58
A method that gets a value from a class's field but does not change it is known as a mutator method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 58 في هذه المجموعة.
فتح الحزمة
k this deck