Deck 10: Introduction to Inheritance

Full screen (f)
exit full mode
Question
The class used as a basis for inheritance is the ____ class.

A) child
B) extends
C) base
D) derived
Use Space or
up arrow
down arrow
to flip the card.
Question
In a UML diagram, an inheritance relationship is indicated with an arrow that points from the original class  to the descendant class  .
Question
A class diagram consists of a rectangle divided into three sections.
Question
____ is a mechanism that enables one class to acquire all the behaviors and attributes of another class.

A) Inheritance
B) Polymorphism
C) Encapsulation
D) Override
Question
Arrows used in a ____ to show inheritance relationships extend from the descendant class and point to the original class.

A) method diagram
B) UML diagram
C) virtual method call
D) composition
Question
Subclasses are more specific than the superclass they extend.
Question
It is useful to override the parent class members when the superclass data fields and methods are not completely appropriate for the subclass objects.
Question
When you use the method name with a child object, the parent's version of the method is used.
Question
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.
Question
A nonstatic method cannot  override a static member  of a parent class.
Question
An error is generated by the compiler when you attempt to override a static method with a nonstatic method.
Question
When you create any subclass object, the subclass constructor  must execute first, and then the superclass constructor  executes.
Question
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
Question
If a programming language does not support ____, the language is not considered object-oriented.

A) syntax
B) applets
C) loops
D) polymorphism
Question
By convention, a class diagram contains the ____ following each attribute or method.

A) data field
B) argument
C) data type
D) class
Question
When you create a class by making it inherit from another class, the new class automatically contains the data fields and _____ of the original class.

A) fonts
B) methods
C) class names
D) arrays
Question
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
Question
You cannot declare a class to be final .
Question
You use the keyword ____ to achieve inheritance in Java.

A) inherit
B) extends
C) super
D) public
Question
____ polymorphism is the ability of one method to work appropriately for subclasses of the same parent class.

A) Subtype
B) Name
C) Supertype
D) Override
Question
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);
Question
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
Question
The classes you create in ____________________ programming languages can inherit data and methods from existing classes.
Question
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
Question
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
Question
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;
Question
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
Question
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
Question
An advantage to making a method ____________________ is that the compiler knows there will be only one version of the method.
Question
Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.

A) objects
B) data fields
C) methods
D) constructors
Question
Using the keyword ____ provides you with an intermediate level of security between public and private access.

A) protected
B) this
C) super
D) secure
Question
In most Java classes, the keyword private precedes each data field, and the keyword ____________________ precedes each method.
Question
Programmers and analysts sometimes use a graphical language to describe classes and object-oriented processes. This language is called ___________________________________.
Question
The term ____________________ means "many forms."
Question
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
Question
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
Question
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
Question
You can use the keyword _______ within a method in a derived class to access an overridden method in a base class.

A) sub
B) this
C) protected
D) super
Question
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
Question
When you create parent and child classes of your own, the child classes use ____ constructors.

A) two
B) three
C) four
D) six
Question
Match between columns
Must be the first statement in the subclass constructor
class diagram
Must be the first statement in the subclass constructor
super()
Must be the first statement in the subclass constructor
inheritance
Must be the first statement in the subclass constructor
superclass
Must be the first statement in the subclass constructor
instanceof
Must be the first statement in the subclass constructor
virtual method call
Must be the first statement in the subclass constructor
inlining
Must be the first statement in the subclass constructor
information hiding
Must be the first statement in the subclass constructor
derived class
Keeps data private
class diagram
Keeps data private
super()
Keeps data private
inheritance
Keeps data private
superclass
Keeps data private
instanceof
Keeps data private
virtual method call
Keeps data private
inlining
Keeps data private
information hiding
Keeps data private
derived class
A part of UML
class diagram
A part of UML
super()
A part of UML
inheritance
A part of UML
superclass
A part of UML
instanceof
A part of UML
virtual method call
A part of UML
inlining
A part of UML
information hiding
A part of UML
derived class
Inherits from a base class
class diagram
Inherits from a base class
super()
Inherits from a base class
inheritance
Inherits from a base class
superclass
Inherits from a base class
instanceof
Inherits from a base class
virtual method call
Inherits from a base class
inlining
Inherits from a base class
information hiding
Inherits from a base class
derived class
A base class
class diagram
A base class
super()
A base class
inheritance
A base class
superclass
A base class
instanceof
A base class
virtual method call
A base class
inlining
A base class
information hiding
A base class
derived class
Determines whether an object is a member or descendant of a class
class diagram
Determines whether an object is a member or descendant of a class
super()
Determines whether an object is a member or descendant of a class
inheritance
Determines whether an object is a member or descendant of a class
superclass
Determines whether an object is a member or descendant of a class
instanceof
Determines whether an object is a member or descendant of a class
virtual method call
Determines whether an object is a member or descendant of a class
inlining
Determines whether an object is a member or descendant of a class
information hiding
Determines whether an object is a member or descendant of a class
derived class
Makes a program run faster
class diagram
Makes a program run faster
super()
Makes a program run faster
inheritance
Makes a program run faster
superclass
Makes a program run faster
instanceof
Makes a program run faster
virtual method call
Makes a program run faster
inlining
Makes a program run faster
information hiding
Makes a program run faster
derived class
A mechanism that enables one class to assume both the behavior and the attributes of another class
class diagram
A mechanism that enables one class to assume both the behavior and the attributes of another class
super()
A mechanism that enables one class to assume both the behavior and the attributes of another class
inheritance
A mechanism that enables one class to assume both the behavior and the attributes of another class
superclass
A mechanism that enables one class to assume both the behavior and the attributes of another class
instanceof
A mechanism that enables one class to assume both the behavior and the attributes of another class
virtual method call
A mechanism that enables one class to assume both the behavior and the attributes of another class
inlining
A mechanism that enables one class to assume both the behavior and the attributes of another class
information hiding
A mechanism that enables one class to assume both the behavior and the attributes of another class
derived class
An instance method call
class diagram
An instance method call
super()
An instance method call
inheritance
An instance method call
superclass
An instance method call
instanceof
An instance method call
virtual method call
An instance method call
inlining
An instance method call
information hiding
An instance method call
derived class
Question
What is information hiding and how is it used?
Question
Create a class named Student that contains methods getGPA() , setIDNum() , and setGPA() . Be sure to declare variables and methods appropriately as public or private.
Question
What happens when you write your own constructor in Java and what must you pay attention to?
Question
What is the difference between derived classes and base classes when considering two classes that inherit from each other?
Question
How is the keyword protected used?
Question
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".
Question
How are real-life examples of inheritance similar to object-oriented programming inheritance?
Question
         Use the above code and sections labeled 1, 2, and 3 to answer the following: Identify the labeled section that is the constructor for the Bicycle class, identify the section of fields of the Bicycle class, and identify the Bicycle class methods.<div style=padding-top: 35px>       
Use the above code and sections labeled 1, 2, and 3 to answer the following:
Identify the labeled section that is the constructor for the Bicycle class, identify the section of fields of the Bicycle class, and identify the Bicycle class methods.
Question
What are virtual method calls?
Question
What does polymorphism mean in Java programming?
Question
What is the process of inlining and how is it accomplished in Java?
Question
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.
Question
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.
Question
Using a class named Student , write the statement to create a yearOne object of the Student class.
Question
When you instantiate an object that is a member of a subclass, how many constructors are called?
Question
Write the statement to create a class header with a superclass-subclass relationship, with Vehicle as the superclass and Subaru as the subclass.
Question
public HourlyEmployee(char dept, double rate, int hours)
{
     ---- code here ----
}
Given the overloaded constructor above, write the appropriate statement that calls the superclass constructor  and passes the indicated arguments to the superclass constructor.
Question
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?
Question
What are the parts of a class diagram and how would you use them?
Question
What are the three types of methods that you cannot override in a subclass?
Question
  The above code will generate an error message when compiling. Explain the error message and why it occurs.<div style=padding-top: 35px>
The above code will generate an error message when compiling. Explain the error message and why it occurs.
Question
  The UML diagram above derives a subclass called EmployeeWithTerritory from the superclass Employee . Describe what variables and methods the class EmployeeWithTerritory  inherits from the superclass Employee .  Also, describe any variables and public methods defined by the subclass EmployeeWithTerritory .<div style=padding-top: 35px>
The UML diagram above derives a subclass called EmployeeWithTerritory from the superclass Employee . Describe what variables and methods the class EmployeeWithTerritory  inherits from the superclass Employee .  Also, describe any variables and public methods defined by the subclass EmployeeWithTerritory .
Question
    Will the above code compile correctly? Why or why not? Explain your answer.<div style=padding-top: 35px>
    Will the above code compile correctly? Why or why not? Explain your answer.<div style=padding-top: 35px>
Will the above code compile correctly? Why or why not? Explain your answer.
Question
public class ASuperClass
{
   public ASuperClass()
   {
      System.out.println("In superclass constructor");
   }
}
public class ASubClass extends ASuperClass
{
   public ASubClass()
   {
      System.out.println("In subclass constructor");
   }
}
public class DemoConstructors
{
   public static void main(String[] args)
   {
      ASubClass child = new ASubClass();
   }
}
Given the above code, what will the output be when DemoConstructors executes?
Question
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?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/66
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: Introduction to Inheritance
1
The class used as a basis for inheritance is the ____ class.

A) child
B) extends
C) base
D) derived
C
2
In a UML diagram, an inheritance relationship is indicated with an arrow that points from the original class  to the descendant class  .
False
3
A class diagram consists of a rectangle divided into three sections.
True
4
____ is a mechanism that enables one class to acquire all the behaviors and attributes of another class.

A) Inheritance
B) Polymorphism
C) Encapsulation
D) Override
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
5
Arrows used in a ____ to show inheritance relationships extend from the descendant class and point to the original class.

A) method diagram
B) UML diagram
C) virtual method call
D) composition
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
6
Subclasses are more specific than the superclass they extend.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
7
It is useful to override the parent class members when the superclass data fields and methods are not completely appropriate for the subclass objects.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
8
When you use the method name with a child object, the parent's version of the method is used.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
9
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.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
10
A nonstatic method cannot  override a static member  of a parent class.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
11
An error is generated by the compiler when you attempt to override a static method with a nonstatic method.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
12
When you create any subclass object, the subclass constructor  must execute first, and then the superclass constructor  executes.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
13
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
14
If a programming language does not support ____, the language is not considered object-oriented.

A) syntax
B) applets
C) loops
D) polymorphism
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
15
By convention, a class diagram contains the ____ following each attribute or method.

A) data field
B) argument
C) data type
D) class
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
16
When you create a class by making it inherit from another class, the new class automatically contains the data fields and _____ of the original class.

A) fonts
B) methods
C) class names
D) arrays
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
17
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
18
You cannot declare a class to be final .
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
19
You use the keyword ____ to achieve inheritance in Java.

A) inherit
B) extends
C) super
D) public
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
20
____ polymorphism is the ability of one method to work appropriately for subclasses of the same parent class.

A) Subtype
B) Name
C) Supertype
D) Override
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
21
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);
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
22
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
23
The classes you create in ____________________ programming languages can inherit data and methods from existing classes.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
25
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
26
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;
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
28
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
29
An advantage to making a method ____________________ is that the compiler knows there will be only one version of the method.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
30
Usually, the subclass constructor only needs to initialize the ____ that are specific to the subclass.

A) objects
B) data fields
C) methods
D) constructors
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
31
Using the keyword ____ provides you with an intermediate level of security between public and private access.

A) protected
B) this
C) super
D) secure
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
32
In most Java classes, the keyword private precedes each data field, and the keyword ____________________ precedes each method.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
33
Programmers and analysts sometimes use a graphical language to describe classes and object-oriented processes. This language is called ___________________________________.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
34
The term ____________________ means "many forms."
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
35
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
36
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
37
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
38
You can use the keyword _______ within a method in a derived class to access an overridden method in a base class.

A) sub
B) this
C) protected
D) super
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
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
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
40
When you create parent and child classes of your own, the child classes use ____ constructors.

A) two
B) three
C) four
D) six
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
Must be the first statement in the subclass constructor
class diagram
Must be the first statement in the subclass constructor
super()
Must be the first statement in the subclass constructor
inheritance
Must be the first statement in the subclass constructor
superclass
Must be the first statement in the subclass constructor
instanceof
Must be the first statement in the subclass constructor
virtual method call
Must be the first statement in the subclass constructor
inlining
Must be the first statement in the subclass constructor
information hiding
Must be the first statement in the subclass constructor
derived class
Keeps data private
class diagram
Keeps data private
super()
Keeps data private
inheritance
Keeps data private
superclass
Keeps data private
instanceof
Keeps data private
virtual method call
Keeps data private
inlining
Keeps data private
information hiding
Keeps data private
derived class
A part of UML
class diagram
A part of UML
super()
A part of UML
inheritance
A part of UML
superclass
A part of UML
instanceof
A part of UML
virtual method call
A part of UML
inlining
A part of UML
information hiding
A part of UML
derived class
Inherits from a base class
class diagram
Inherits from a base class
super()
Inherits from a base class
inheritance
Inherits from a base class
superclass
Inherits from a base class
instanceof
Inherits from a base class
virtual method call
Inherits from a base class
inlining
Inherits from a base class
information hiding
Inherits from a base class
derived class
A base class
class diagram
A base class
super()
A base class
inheritance
A base class
superclass
A base class
instanceof
A base class
virtual method call
A base class
inlining
A base class
information hiding
A base class
derived class
Determines whether an object is a member or descendant of a class
class diagram
Determines whether an object is a member or descendant of a class
super()
Determines whether an object is a member or descendant of a class
inheritance
Determines whether an object is a member or descendant of a class
superclass
Determines whether an object is a member or descendant of a class
instanceof
Determines whether an object is a member or descendant of a class
virtual method call
Determines whether an object is a member or descendant of a class
inlining
Determines whether an object is a member or descendant of a class
information hiding
Determines whether an object is a member or descendant of a class
derived class
Makes a program run faster
class diagram
Makes a program run faster
super()
Makes a program run faster
inheritance
Makes a program run faster
superclass
Makes a program run faster
instanceof
Makes a program run faster
virtual method call
Makes a program run faster
inlining
Makes a program run faster
information hiding
Makes a program run faster
derived class
A mechanism that enables one class to assume both the behavior and the attributes of another class
class diagram
A mechanism that enables one class to assume both the behavior and the attributes of another class
super()
A mechanism that enables one class to assume both the behavior and the attributes of another class
inheritance
A mechanism that enables one class to assume both the behavior and the attributes of another class
superclass
A mechanism that enables one class to assume both the behavior and the attributes of another class
instanceof
A mechanism that enables one class to assume both the behavior and the attributes of another class
virtual method call
A mechanism that enables one class to assume both the behavior and the attributes of another class
inlining
A mechanism that enables one class to assume both the behavior and the attributes of another class
information hiding
A mechanism that enables one class to assume both the behavior and the attributes of another class
derived class
An instance method call
class diagram
An instance method call
super()
An instance method call
inheritance
An instance method call
superclass
An instance method call
instanceof
An instance method call
virtual method call
An instance method call
inlining
An instance method call
information hiding
An instance method call
derived class
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
42
What is information hiding and how is it used?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
43
Create a class named Student that contains methods getGPA() , setIDNum() , and setGPA() . Be sure to declare variables and methods appropriately as public or private.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
44
What happens when you write your own constructor in Java and what must you pay attention to?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
45
What is the difference between derived classes and base classes when considering two classes that inherit from each other?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
46
How is the keyword protected used?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
47
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".
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
48
How are real-life examples of inheritance similar to object-oriented programming inheritance?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
49
         Use the above code and sections labeled 1, 2, and 3 to answer the following: Identify the labeled section that is the constructor for the Bicycle class, identify the section of fields of the Bicycle class, and identify the Bicycle class methods.       
Use the above code and sections labeled 1, 2, and 3 to answer the following:
Identify the labeled section that is the constructor for the Bicycle class, identify the section of fields of the Bicycle class, and identify the Bicycle class methods.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
50
What are virtual method calls?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
51
What does polymorphism mean in Java programming?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
52
What is the process of inlining and how is it accomplished in Java?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
53
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.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
54
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.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
55
Using a class named Student , write the statement to create a yearOne object of the Student class.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
56
When you instantiate an object that is a member of a subclass, how many constructors are called?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
57
Write the statement to create a class header with a superclass-subclass relationship, with Vehicle as the superclass and Subaru as the subclass.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
58
public HourlyEmployee(char dept, double rate, int hours)
{
     ---- code here ----
}
Given the overloaded constructor above, write the appropriate statement that calls the superclass constructor  and passes the indicated arguments to the superclass constructor.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
59
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?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
60
What are the parts of a class diagram and how would you use them?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
61
What are the three types of methods that you cannot override in a subclass?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
62
  The above code will generate an error message when compiling. Explain the error message and why it occurs.
The above code will generate an error message when compiling. Explain the error message and why it occurs.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
63
  The UML diagram above derives a subclass called EmployeeWithTerritory from the superclass Employee . Describe what variables and methods the class EmployeeWithTerritory  inherits from the superclass Employee .  Also, describe any variables and public methods defined by the subclass EmployeeWithTerritory .
The UML diagram above derives a subclass called EmployeeWithTerritory from the superclass Employee . Describe what variables and methods the class EmployeeWithTerritory  inherits from the superclass Employee .  Also, describe any variables and public methods defined by the subclass EmployeeWithTerritory .
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
64
    Will the above code compile correctly? Why or why not? Explain your answer.
    Will the above code compile correctly? Why or why not? Explain your answer.
Will the above code compile correctly? Why or why not? Explain your answer.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
65
public class ASuperClass
{
   public ASuperClass()
   {
      System.out.println("In superclass constructor");
   }
}
public class ASubClass extends ASuperClass
{
   public ASubClass()
   {
      System.out.println("In subclass constructor");
   }
}
public class DemoConstructors
{
   public static void main(String[] args)
   {
      ASubClass child = new ASubClass();
   }
}
Given the above code, what will the output be when DemoConstructors executes?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
66
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?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 66 flashcards in this deck.