Questions and Answers
What is a form of software reusability in which new classes acquire the members of existing classes?
Inheritance
A has-a relationship is implemented via inheritance.
False
In a(n) _______ relationship, a class object has references to objects of other classes as members.
has-a
What is the superclass constructor call syntax?
Signup and view all the answers
A superclass's ____________ and ___________ members can be accessed in the superclass declaration and in subclass declarations.
Signup and view all the answers
Inheritance is sometimes referred to as what?
Signup and view all the answers
Which statement is true when a superclass has protected instance variables?
Signup and view all the answers
Superclass constructors are inherited by subclasses.
Signup and view all the answers
What type of superclass does a subclass explicitly inherit from?
Signup and view all the answers
This access modifier offers an intermediate level of access.
Signup and view all the answers
In a(n) ______ relationship, an object of a subclass can also be treated as an object of its superclass.
Signup and view all the answers
How can fields labeled private in a superclass be accessed in a subclass?
Signup and view all the answers
Superclass methods with this level of access cannot be called from subclasses.
Signup and view all the answers
Every class in Java, except ________, extends an existing class.
Signup and view all the answers
Subclass constructors can call superclass constructors via the keyword _________.
Signup and view all the answers
A Car class has a has-a relationship with the Vehicle class.
Signup and view all the answers
Overriding a method differs from overloading a method because?
Signup and view all the answers
Choose the answer that lists the complete set of statements that are true:
Signup and view all the answers
What is the relationship termed as when a class is derived from another?
Signup and view all the answers
Inheritance is also known as the
Signup and view all the answers
Private fields of a superclass can be accessed in a subclass
Signup and view all the answers
In single inheritance, a class exists in a(n) _______________ relationship with its subclasses.
Signup and view all the answers
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?
Signup and view all the answers
Which of the following statements is (are) true?
Signup and view all the answers
When a subclass redefines a superclass method by using the same signature, the subclass is said to overload that superclass method.
Signup and view all the answers
A superclass object is a subclass object.
Signup and view all the answers
Which of the following is not a superclass/subclass relationship?
Signup and view all the answers
An advantage of inheritance is that?
Signup and view all the answers
Using the protected keyword gives a member?
Signup and view all the answers
To avoid duplicating code, use ________, rather than ________.
Signup and view all the answers
Which of the following statements describes the state of instance variables after the constructor for class B executes?
Signup and view all the answers
Which superclass members are inherited by all subclasses of that superclass?
Signup and view all the answers
Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass's method causes what?
Signup and view all the answers
When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable?
Signup and view all the answers
Which of the following is an example of a functionality that should not be 'factored out' to a superclass?
Signup and view all the answers
The default implementation of method clone of Object performs a?
Signup and view all the answers
The default equals implementation determines?
Signup and view all the answers
Class ________ represents an image that can be displayed on a JLabel.
Signup and view all the answers
Which method changes the text the label displays?
Signup and view all the answers
Polymorphism enables you to?
Signup and view all the answers
If the superclass contains only abstract method declarations, the superclass is used for?
Signup and view all the answers
Answer by choosing the correct set of true statements:
Signup and view all the answers
Which of the following does not complete the sentence correctly? An interface
Signup and view all the answers
Classes and methods are declared final for all but the following reasons:
Signup and view all the answers
Classes from which objects can be instantiated are called?
Signup and view all the answers
Assigning a subclass reference to a superclass variable is safe.
Signup and view all the answers
If a class contains at least one abstract method, it's a(n) ___________ class.
Signup and view all the answers
For which of the following would polymorphism not provide a clean solution?
Signup and view all the answers
All methods in an abstract class must be declared as abstract methods.
Signup and view all the answers
Which of the following statements about abstract superclasses is true?
Signup and view all the answers
An interface may contain?
Signup and view all the answers
To use an interface, a concrete class must specify that it implements the interface and must declare each method in the interface with the signature specified in the interface declaration.
Signup and view all the answers
Which of the following statements about interfaces is false?
Signup and view all the answers
Which statement best describes the relationship between superclass and subclass types?
Signup and view all the answers
Non-abstract classes are called:
Signup and view all the answers
Consider classes A, B, and C, where A is an abstract superclass, B is a concrete class that inherits from A, and C is a concrete class that inherits from B. Which of the following statements is true of class C?
Signup and view all the answers
Failure to implement a superclass's abstract methods in a subclass is a compilation error unless the subclass is also declared abstract.
Signup and view all the answers
Polymorphism allows for specifics to be dealt with during?
Signup and view all the answers
Consider the abstract superclass below: public abstract class Foo { private int a; public int b; public Foo( int aVal, int bVal ) { a = aVal; b = bVal; } public abstract int calculate(); } Any concrete subclass that extends class Foo:
Signup and view all the answers
Which keyword is used to specify that a class will define the methods of an interface?
Signup and view all the answers
All of the following methods are implicitly final except:
Signup and view all the answers
This type of class cannot be a superclass.
Signup and view all the answers
It is a UML convention to denote the name of an abstract class in?
Signup and view all the answers
A(n) class cannot be instantiated.
Signup and view all the answers
Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?
Signup and view all the answers
When a superclass variable refers to a subclass object and a method is called on that object, the proper implementation is determined at?
Signup and view all the answers
Every object in Java knows its own class and can access this information through the method?
Signup and view all the answers
Declaring a method final means?
Signup and view all the answers
The UML distinguishes an interface from other classes by placing the word 'interface' in?
Signup and view all the answers
Interfaces can have methods.
Signup and view all the answers
Which of the following is not possible?
Signup and view all the answers
A class that implements an interface but does not declare all of the interface's methods must be declared?
Signup and view all the answers
Constants declared in an interface are implicitly?
Signup and view all the answers
In a class diagram, properties may be related to the instance variables of a class.
Signup and view all the answers
It is permissible to leave get and set methods for the instance variables of a class out of the class diagram.
Signup and view all the answers
Which of the following statements describe the type(s) of relationships that may be described by class diagrams?
Signup and view all the answers
Operations in a class diagram correspond to _____ in Java.
Signup and view all the answers
The proper way to indicate that a class property may have no value entered into it is ____________.
Signup and view all the answers
Which of the following may be represented in a class diagram?
Signup and view all the answers
The UML syntax for operations includes which of the following:
Signup and view all the answers
The features of a class can refer to both properties and operations.
Signup and view all the answers
Which of the following may be found in an attribute notation (select all that apply)?
Signup and view all the answers
Whether an operation is public or private is indicated by either + for private or - for public.
Signup and view all the answers
Something a business must track or that participates in the business may generally be called?
Signup and view all the answers
Which of the following should be visible to other objects?
Signup and view all the answers
Another way to talk about a superclass is?
Signup and view all the answers
The acronym OMG (when discussing UML) stands for which of the following?
Signup and view all the answers
Polymorphism refers to the ability of _________ to take many 'shapes'.
Signup and view all the answers
A subclass may add attributes, operations, and relationships to those inherited from the superclass.
Signup and view all the answers
Polymorphism allows a subclass to override operations of a superclass, thus specializing the operation for the subclass.
Signup and view all the answers
The UML standard is owned by which of the following?
Signup and view all the answers
An object of a subclass automatically?
Signup and view all the answers
If two objects belong to the same class, which of the following statements about those objects is true?
Signup and view all the answers
A superclass defines a method called findArea. A subclass of that superclass also defines a method called findArea, but the subclass method uses a different formula. This is an example of ________.
Signup and view all the answers
A 'method' is?
Signup and view all the answers
Two things that must be remembered about specific objects are (select two):
Signup and view all the answers
The ways objects may be related are?
Signup and view all the answers
Attributes and operations defined at the class level will be shared by all objects of that class.
Signup and view all the answers
Study Notes
Inheritance and Relationships
- Inheritance allows new classes to inherit properties and methods from existing classes, enhancing functionality.
- A has-a relationship indicates composition, not inheritance, which defines relationships where a class contains references to other classes.
- An is-a relationship means a subclass can be treated as an object of its superclass.
Access Modifiers
- Protected members can be accessed by subclasses and other classes within the same package.
- Public members are accessible everywhere, whereas private members of a superclass can only be accessed through public or protected methods.
Constructors
- Superclass constructors are not inherited; subclasses must call them explicitly using the
super
keyword. - When invoking an abstract superclass, subclasses must implement the abstract methods or also be declared abstract.
Abstract Classes and Interfaces
- Abstract classes can include both abstract methods and concrete methods and cannot be instantiated directly.
- Interfaces only define abstract methods (implicitly public) and constants (implicitly static final) and cannot be instantiated.
Polymorphism
- Polymorphism allows methods to be overridden, enabling subclasses to provide specific implementations of superclass methods.
- Late binding refers to method resolution at runtime, allowing subclass methods to be called when using superclass references.
UML and Class Diagrams
- UML notation distinguishes between classes and interfaces by formatting, using italics for abstract classes and guillemets for interfaces.
- Class diagrams represent relationships like inheritance, composition, and define properties (attributes) and behaviors (methods) of classes.
Relationships in Java
- Relationships between classes include association, aggregation, and composition, determining how objects interact and are linked.
- Subclass objects inherit all attributes and methods from their superclass and can define additional features, enhancing reusability and reducing redundancy.
Truths About Classes and Objects
- Objects of the same class share the same operational procedures but may hold different attribute values.
- Declaring a method as final prevents it from being overridden, maintaining its original behavior across subclasses.
Important Concepts in Java
- The
super
keyword is essential for accessing superclass methods and constructors from within subclasses, especially when methods are overridden. - Constructors of subclasses must always call their direct superclass constructor as their first task, ensuring proper initialization of inherited attributes.
Key Definitions
- Concrete classes can be instantiated, unlike abstract classes which provide foundational structures but require derived classes to implement specifics.
- Business objects reflect entities of interest within a business context and must expose certain operations while encapsulating their attributes.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge with these flashcards designed for the IS2043 Exam One. Topics covered include software reusability, inheritance, and class relationships. Perfect for reinforcing key concepts in your software development studies.