Deck 10: Introduction to Inheritance

ملء الشاشة (f)
exit full mode
سؤال
The ability to use inheritance in Java makes programs easier to write, ____, and more quickly understood.

A) faster
B) more secure
C) more robust
D) less error prone
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
If a programming language does not support ____, the language is not considered object-oriented.

A) syntax
B) applets
C) loops
D) polymorphism
سؤال
The class used as a basis for inheritance is the ____ class.

A) child
B) extends
C) base
D) derived
سؤال
When a protected data field or method is created, it can be used within its own class or in any classes extended from that class; but it cannot be used by outside classes.
سؤال
You use the keyword ____ to achieve inheritance in Java.

A) inherit
B) extends
C) super
D) public
سؤال
Java's Math class is an example of a protected class.
سؤال
Superclasses can be distinguished from their subclasses because a subclass is generally smaller than a superclass; it usually has fewer fields and methods.
سؤال
An error is generated by the compiler when you attempt to override a static method with a nonstatic method.
سؤال
____ is the principle that allows you to apply your knowledge of a general category to more specific objects.

A) Inheritance
B) Polymorphism
C) Encapsulation
D) Override
سؤال
If a superclass contains only constructors that require arguments, you do not need to create a subclass constructor.
سؤال
When you use the method name with a child object, the parent's version of the method is used.
سؤال
A class diagram consists of a rectangle divided into three sections.
سؤال
By convention, a class diagram contains the ____ following each attribute or method.

A) data field
B) argument
C) data type
D) class
سؤال
____ polymorphism is the ability of one method name to work appropriately for different subclass objects of the same parent class.

A) Subtype
B) Name
C) Supertype
D) Override
سؤال
Conventionally, arrows used in a ____ to show inheritance relationships extend from the descendant class and point to the one from which it descends.

A) method diagram
B) UML diagram
C) virtual method call
D) composition
سؤال
In a UML diagram, minus signs are inserted in front of each private field or method, and plus signs are inserted in front of each public field or method.
سؤال
It is useful to override the parent class members when the superclass data fields and methods are not completely appropriate for the subclass objects.
سؤال
Sometimes the superclass data fields and methods are not entirely appropriate for the subclass objects; in these cases, you want to ____ the parent class members.

A) negate
B) overrule
C) override
D) hide
سؤال
When you create a class by making it inherit from another class, you are provided with data fields and ____ automatically.

A) fonts
B) methods
C) class names
D) arrays
سؤال
A static method cannot be overridden in a subclass.
سؤال
An advantage to making a method ____________________ is that the compiler knows there will be only one version of the method.
سؤال
Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.

A) objects
B) data fields
C) methods
D) constructors
سؤال
Which statement correctly declares a sedan object of the Car class?

A) sedan Car = new sedan();
B) sedan Car = new sedan();
C) Car sedan = new Car();
D) new sedan() = Student;
سؤال
You can use the ____ modifier with methods when you don't want the method to be overridden.

A) override
B) access
C) final
D) end
سؤال
In most Java classes, the keyword private precedes each data field, and the keyword ____________________ precedes each method.
سؤال
When you create parent and child classes of your own, the child classes use ____ constructors.

A) two
B) three
C) four
D) six
سؤال
When you employ ____, your data can be altered only by the methods you choose and only in ways that you can control.

A) virtual method calls
B) polymorphism
C) information hiding
D) inlining
سؤال
Using the keyword ____ provides you with an intermediate level of security between public and private access.

A) protected
B) this
C) super
D) secure
سؤال
If jrStudent is an object of Student, which of the following statements will result in a value of true?

A) Student = instanceof jrStudent
B) jrStudent instanceof Student
C) instanceof Student = jrStudent
D) Student instanceof jrStudent
سؤال
Within a subclass, you can think of the keyword ____ as the opposite of super.

A) sub
B) this
C) protected
D) not
سؤال
The classes you create in ____________________ programming languages can inherit data and methods from existing classes.
سؤال
Which of the following statements depicts the valid format to call a superclass constructor from a subclass constructor?

A) superclass(name, score);
B) subclass(name, score);
C) extends(name, score);
D) super(name, score);
سؤال
Which of the following statements will create a class named Red that is based on the class Color?

A) public class Red extends Color
B) public Red class extends Color
C) public Color class expands Red
D) public extend Red class Color
سؤال
The methods in a subclass can use all of the data fields and methods that belong to its parent, with one exception: ____ members of the parent class are not accessible within a child class's methods.

A) private
B) public
C) final
D) protected
سؤال
The term ____________________ means "many forms."
سؤال
When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.

A) constructor
B) argument
C) header
D) name
سؤال
If a ____ method has the same name as a parent class method and you use the name with a child class object, the child method hides the original.

A) final
B) static
C) protected
D) private
سؤال
You are never aware that ____ is taking place; the compiler chooses to use this procedure to save the overhead of calling a method.

A) information hiding
B) polymorphism
C) overriding
D) inlining
سؤال
You would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?

A) private or protected
B) private
C) protected
D) public
سؤال
Programmers and analysts sometimes use a graphical language to describe classes and object-oriented processes. This language is called ___________________________________.
سؤال
What are virtual method calls?
سؤال
What is the process of inlining and how is it accomplished in Java?
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Makes a program run faster
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Inherits from a base class
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
An instance method call
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Determines whether an object is a member or descendant of a class
سؤال
Write the statement to create a class header with a superclass-subclass relationship, with Vehicle as the superclass and Subaru as the subclass.
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
A mechanism that enables one class to assume both the behavior and the attributes of another class
سؤال
When you instantiate an object that is a member of a subclass, how many constructors are called?
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
A part of UML
سؤال
What happens when you write your own constructor in Java and what must you pay attention to?
سؤال
What is information hiding and how is it used?
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Must be the first statement in the subclass constructor
سؤال
What does polymorphism mean in Java programming?
سؤال
What is the difference between derived classes and base classes when considering two classes that inherit from each other?
سؤال
How is the keyword protected used?
سؤال
What are the parts of a class diagram and how would you use them?
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
A base class
سؤال
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Keeps data private
سؤال
How are real-life examples of inheritance similar to object-oriented programming inheritance?
سؤال
class Animal
{
void myDog()
{
System.out.println("Animal stuff");
}
}
class Dog extends Animal
{
void mydog()
{
System.out.println("Dog stuff");
}
public static void main(String args[])
{
Dog d = new Dog();
d.myDog();
super.myDog();
}
}
The above code gives a compiler error stating that the non-static variable super cannot be
referenced from a static context super.myDog();. Explain why the error occurs and describe what changes you could make for the code to be executable.
سؤال
public class Student
{
private String firstName;
private String lastName;
private String address;
private String username;
public Student(String studentFirstName, String StudentLastName, String studentAddress String studentUsername)
{
firstName = studentFirstName;
lastName = studentLastName;
address = studentAddress;
username = studentUsername;
}
}
public void displayStudentInfo()
{
System.out.println("Name: " + firstName + " " + lastName);
System.out.println("Address: " + address);
System.out.println("Username: " + username);
}
Using the above code, call the constructor to create a new instance of the Student object named joe. The constructor method will take the four string values (first name, last name, address, username) and set the initial state of the Student object to be: firstname = "Joe", lastname = "Jones", address = "123 Oak St.", username = "JJones".
سؤال
class InstanceofDemo
{
public static void main(String[] args)
{
Parent object1 = new Parent();
Parent object2 = new Child();
System.out.println("object1 instanceof Parent: "
+ (obj1 instanceof Parent));
System.out.println("object1 instanceof Child: "
+ (obj1 instanceof Child));
System.out.println("object1 instanceof MyInterface: "
+ (obj1 instanceof MyInterface));
System.out.println("object2 instanceof Parent: "
+ (obj2 instanceof Parent));
System.out.println("object2 instanceof Child: "
+ (obj2 instanceof Child));
System.out.println("object2 instanceof MyInterface: "
+ (obj2 instanceof MyInterface));
}
}
The above code defines a parent class (named Parent), a simple interface (named MyInterface), and a child class (named Child) that inherits from the parent and implements the interface.
Following program execution, what will be the output of the six println statements?
سؤال
class Vehicle {}
public class Car extends Vehicle
{
public static void main(String args[])
{
Vehicle myCar = new Car();
boolean result = myCar instanceof Car;
System.out.println(result);
}
}
The above code uses the instanceof operator to determine whether an object is a member of a class. What will be the output following execution?
سؤال
public class Student
{
private String firstName;
private String lastName;
private String address;
private String username;
public Student(String studentFirstName, String StudentLastName, String studentAddress String studentUsername)
{
firstName = studentFirstName;
lastName = studentLastName;
address = studentAddress;
username = studentUsername;
}
}
Create a method called displayStudentInfo that will display the value of the first name, last name, address, and username objects using println() statements.
سؤال
Using a class named Student, write the statement to create a yearOne object of the Student class.
سؤال
Create a class named Employee with a name and a salary. Make a class named Manager that inherits from Employee with an instance field named department. Supply a toString() method that prints the manager's name, department, and salary. Make another class named Director that inherits from Manager with an instance field named stipendAmount. Supply the toString() method for Director that prints all of its instance variables. Also, write a program named myOutput that instantiates an object of each of the classes and invokes the toString() method of each of the objects.
سؤال
public class Student
{
private String firstName;
private String lastName;
private String address;
private String username;
public Student(String ____, String ____, String ____, String ____)
{
____ = ____;
____ = ____;
____ = ____:
____ = ____;
}
}
In the shaded areas provided, create a constructor that accepts the values of the student's first name, last name, address, and username. Use these values to set the initial state of the object.
سؤال
You have a Student class with a constructor that requires two arguments: a character "F" for Freshman and an integer "2020" for the year. Create a Freshman class that is a subclass of Student with a constructor for Freshman. Include the initial super() statement and include a comment that reads "//Other statements go here".
سؤال
Create a class named Account that contains an integer field for an account number and a double field for an account balance. The class contains a constructor that requires an account number and sets the balance to 0.0. Include a set() method for the balance, a get() method for the account number, and a get() method for the account balance. Create two subclasses named Checking and Savings. Within the Checking class, the get() method should display the String "Checking Account Information", the account number, and the balance. Within the Savings class, add a field to hold the interest rate, and require the Savings constructor to accept an argument for the value of the interest rate. The Savings get() method displays the String "Savings Account Information", the account number, the balance, and the interest.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/70
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 10: Introduction to Inheritance
1
The ability to use inheritance in Java makes programs easier to write, ____, and more quickly understood.

A) faster
B) more secure
C) more robust
D) less error prone
D
2
If a programming language does not support ____, the language is not considered object-oriented.

A) syntax
B) applets
C) loops
D) polymorphism
D
3
The class used as a basis for inheritance is the ____ class.

A) child
B) extends
C) base
D) derived
C
4
When a protected data field or method is created, it can be used within its own class or in any classes extended from that class; but it cannot be used by outside classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
5
You use the keyword ____ to achieve inheritance in Java.

A) inherit
B) extends
C) super
D) public
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
6
Java's Math class is an example of a protected class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
7
Superclasses can be distinguished from their subclasses because a subclass is generally smaller than a superclass; it usually has fewer fields and methods.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
8
An error is generated by the compiler when you attempt to override a static method with a nonstatic method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
9
____ is the principle that allows you to apply your knowledge of a general category to more specific objects.

A) Inheritance
B) Polymorphism
C) Encapsulation
D) Override
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
10
If a superclass contains only constructors that require arguments, you do not need to create a subclass constructor.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
11
When you use the method name with a child object, the parent's version of the method is used.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
12
A class diagram consists of a rectangle divided into three sections.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
13
By convention, a class diagram contains the ____ following each attribute or method.

A) data field
B) argument
C) data type
D) class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
14
____ polymorphism is the ability of one method name to work appropriately for different subclass objects of the same parent class.

A) Subtype
B) Name
C) Supertype
D) Override
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
15
Conventionally, arrows used in a ____ to show inheritance relationships extend from the descendant class and point to the one from which it descends.

A) method diagram
B) UML diagram
C) virtual method call
D) composition
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
16
In a UML diagram, minus signs are inserted in front of each private field or method, and plus signs are inserted in front of each public field or method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
17
It is useful to override the parent class members when the superclass data fields and methods are not completely appropriate for the subclass objects.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
18
Sometimes the superclass data fields and methods are not entirely appropriate for the subclass objects; in these cases, you want to ____ the parent class members.

A) negate
B) overrule
C) override
D) hide
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
19
When you create a class by making it inherit from another class, you are provided with data fields and ____ automatically.

A) fonts
B) methods
C) class names
D) arrays
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
20
A static method cannot be overridden in a subclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
21
An advantage to making a method ____________________ is that the compiler knows there will be only one version of the method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
22
Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.

A) objects
B) data fields
C) methods
D) constructors
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
23
Which statement correctly declares a sedan object of the Car class?

A) sedan Car = new sedan();
B) sedan Car = new sedan();
C) Car sedan = new Car();
D) new sedan() = Student;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
24
You can use the ____ modifier with methods when you don't want the method to be overridden.

A) override
B) access
C) final
D) end
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
25
In most Java classes, the keyword private precedes each data field, and the keyword ____________________ precedes each method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
26
When you create parent and child classes of your own, the child classes use ____ constructors.

A) two
B) three
C) four
D) six
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
27
When you employ ____, your data can be altered only by the methods you choose and only in ways that you can control.

A) virtual method calls
B) polymorphism
C) information hiding
D) inlining
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
28
Using the keyword ____ provides you with an intermediate level of security between public and private access.

A) protected
B) this
C) super
D) secure
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
29
If jrStudent is an object of Student, which of the following statements will result in a value of true?

A) Student = instanceof jrStudent
B) jrStudent instanceof Student
C) instanceof Student = jrStudent
D) Student instanceof jrStudent
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
30
Within a subclass, you can think of the keyword ____ as the opposite of super.

A) sub
B) this
C) protected
D) not
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
31
The classes you create in ____________________ programming languages can inherit data and methods from existing classes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
32
Which of the following statements depicts the valid format to call a superclass constructor from a subclass constructor?

A) superclass(name, score);
B) subclass(name, score);
C) extends(name, score);
D) super(name, score);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which of the following statements will create a class named Red that is based on the class Color?

A) public class Red extends Color
B) public Red class extends Color
C) public Color class expands Red
D) public extend Red class Color
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
34
The methods in a subclass can use all of the data fields and methods that belong to its parent, with one exception: ____ members of the parent class are not accessible within a child class's methods.

A) private
B) public
C) final
D) protected
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
35
The term ____________________ means "many forms."
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
36
When you create a class and do not provide a(n) ____, Java automatically supplies you with a default one.

A) constructor
B) argument
C) header
D) name
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
37
If a ____ method has the same name as a parent class method and you use the name with a child class object, the child method hides the original.

A) final
B) static
C) protected
D) private
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
38
You are never aware that ____ is taking place; the compiler chooses to use this procedure to save the overhead of calling a method.

A) information hiding
B) polymorphism
C) overriding
D) inlining
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
39
You would like to make a member of a class visible in all subclasses regardless of what package they are in. Which one of the following keywords would achieve this?

A) private or protected
B) private
C) protected
D) public
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
40
Programmers and analysts sometimes use a graphical language to describe classes and object-oriented processes. This language is called ___________________________________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
41
What are virtual method calls?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
42
What is the process of inlining and how is it accomplished in Java?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
43
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Makes a program run faster
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
44
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Inherits from a base class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
45
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
An instance method call
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
46
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Determines whether an object is a member or descendant of a class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
47
Write the statement to create a class header with a superclass-subclass relationship, with Vehicle as the superclass and Subaru as the subclass.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
48
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
A mechanism that enables one class to assume both the behavior and the attributes of another class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
49
When you instantiate an object that is a member of a subclass, how many constructors are called?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
50
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
A part of UML
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
51
What happens when you write your own constructor in Java and what must you pay attention to?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
52
What is information hiding and how is it used?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
53
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Must be the first statement in the subclass constructor
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
54
What does polymorphism mean in Java programming?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
55
What is the difference between derived classes and base classes when considering two classes that inherit from each other?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
56
How is the keyword protected used?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
57
What are the parts of a class diagram and how would you use them?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
58
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
A base class
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
59
Match each term with the correct statement below.
a.information hiding
f.virtual method call
b.inheritance
g.inlining
c.super()
h.class diagram
d.superclass
i.derived class
e.instanceof
Keeps data private
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
60
How are real-life examples of inheritance similar to object-oriented programming inheritance?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
61
class Animal
{
void myDog()
{
System.out.println("Animal stuff");
}
}
class Dog extends Animal
{
void mydog()
{
System.out.println("Dog stuff");
}
public static void main(String args[])
{
Dog d = new Dog();
d.myDog();
super.myDog();
}
}
The above code gives a compiler error stating that the non-static variable super cannot be
referenced from a static context super.myDog();. Explain why the error occurs and describe what changes you could make for the code to be executable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
62
public class Student
{
private String firstName;
private String lastName;
private String address;
private String username;
public Student(String studentFirstName, String StudentLastName, String studentAddress String studentUsername)
{
firstName = studentFirstName;
lastName = studentLastName;
address = studentAddress;
username = studentUsername;
}
}
public void displayStudentInfo()
{
System.out.println("Name: " + firstName + " " + lastName);
System.out.println("Address: " + address);
System.out.println("Username: " + username);
}
Using the above code, call the constructor to create a new instance of the Student object named joe. The constructor method will take the four string values (first name, last name, address, username) and set the initial state of the Student object to be: firstname = "Joe", lastname = "Jones", address = "123 Oak St.", username = "JJones".
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
63
class InstanceofDemo
{
public static void main(String[] args)
{
Parent object1 = new Parent();
Parent object2 = new Child();
System.out.println("object1 instanceof Parent: "
+ (obj1 instanceof Parent));
System.out.println("object1 instanceof Child: "
+ (obj1 instanceof Child));
System.out.println("object1 instanceof MyInterface: "
+ (obj1 instanceof MyInterface));
System.out.println("object2 instanceof Parent: "
+ (obj2 instanceof Parent));
System.out.println("object2 instanceof Child: "
+ (obj2 instanceof Child));
System.out.println("object2 instanceof MyInterface: "
+ (obj2 instanceof MyInterface));
}
}
The above code defines a parent class (named Parent), a simple interface (named MyInterface), and a child class (named Child) that inherits from the parent and implements the interface.
Following program execution, what will be the output of the six println statements?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
64
class Vehicle {}
public class Car extends Vehicle
{
public static void main(String args[])
{
Vehicle myCar = new Car();
boolean result = myCar instanceof Car;
System.out.println(result);
}
}
The above code uses the instanceof operator to determine whether an object is a member of a class. What will be the output following execution?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
65
public class Student
{
private String firstName;
private String lastName;
private String address;
private String username;
public Student(String studentFirstName, String StudentLastName, String studentAddress String studentUsername)
{
firstName = studentFirstName;
lastName = studentLastName;
address = studentAddress;
username = studentUsername;
}
}
Create a method called displayStudentInfo that will display the value of the first name, last name, address, and username objects using println() statements.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
66
Using a class named Student, write the statement to create a yearOne object of the Student class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
67
Create a class named Employee with a name and a salary. Make a class named Manager that inherits from Employee with an instance field named department. Supply a toString() method that prints the manager's name, department, and salary. Make another class named Director that inherits from Manager with an instance field named stipendAmount. Supply the toString() method for Director that prints all of its instance variables. Also, write a program named myOutput that instantiates an object of each of the classes and invokes the toString() method of each of the objects.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
68
public class Student
{
private String firstName;
private String lastName;
private String address;
private String username;
public Student(String ____, String ____, String ____, String ____)
{
____ = ____;
____ = ____;
____ = ____:
____ = ____;
}
}
In the shaded areas provided, create a constructor that accepts the values of the student's first name, last name, address, and username. Use these values to set the initial state of the object.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
69
You have a Student class with a constructor that requires two arguments: a character "F" for Freshman and an integer "2020" for the year. Create a Freshman class that is a subclass of Student with a constructor for Freshman. Include the initial super() statement and include a comment that reads "//Other statements go here".
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
70
Create a class named Account that contains an integer field for an account number and a double field for an account balance. The class contains a constructor that requires an account number and sets the balance to 0.0. Include a set() method for the balance, a get() method for the account number, and a get() method for the account balance. Create two subclasses named Checking and Savings. Within the Checking class, the get() method should display the String "Checking Account Information", the account number, and the balance. Within the Savings class, add a field to hold the interest rate, and require the Savings constructor to accept an argument for the value of the interest rate. The Savings get() method displays the String "Savings Account Information", the account number, the balance, and the interest.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 70 في هذه المجموعة.