IS2043 Exam One Flashcards
98 Questions
100 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

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?

<p>keyword super, followed by a set of parentheses containing the superclass constructor arguments.</p> Signup and view all the answers

A superclass's ____________ and ___________ members can be accessed in the superclass declaration and in subclass declarations.

<p>public and protected</p> Signup and view all the answers

Inheritance is sometimes referred to as what?

<p>specialization</p> Signup and view all the answers

Which statement is true when a superclass has protected instance variables?

<p>All of the above</p> Signup and view all the answers

Superclass constructors are inherited by subclasses.

<p>False</p> Signup and view all the answers

What type of superclass does a subclass explicitly inherit from?

<p>direct superclass</p> Signup and view all the answers

This access modifier offers an intermediate level of access.

<p>protected</p> 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.

<p>is-a</p> Signup and view all the answers

How can fields labeled private in a superclass be accessed in a subclass?

<p>by calling public or protected methods declared in the superclass.</p> Signup and view all the answers

Superclass methods with this level of access cannot be called from subclasses.

<p>True</p> Signup and view all the answers

Every class in Java, except ________, extends an existing class.

<p>Object</p> Signup and view all the answers

Subclass constructors can call superclass constructors via the keyword _________.

<p>super</p> Signup and view all the answers

A Car class has a has-a relationship with the Vehicle class.

<p>False</p> Signup and view all the answers

Overriding a method differs from overloading a method because?

<p>overridden methods have the same signature.</p> Signup and view all the answers

Choose the answer that lists the complete set of statements that are true:

<p>A superclass method can be overridden in a subclass.</p> Signup and view all the answers

What is the relationship termed as when a class is derived from another?

<p>superclass</p> Signup and view all the answers

Inheritance is also known as the

<p>is-a relationship.</p> Signup and view all the answers

Private fields of a superclass can be accessed in a subclass

<p>by calling public or protected methods declared in the superclass.</p> Signup and view all the answers

In single inheritance, a class exists in a(n) _______________ relationship with its subclasses.

<p>hierarchical</p> 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?

<p>super</p> Signup and view all the answers

Which of the following statements is (are) true?

<p>We can use inheritance to customize existing software.</p> 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.

<p>False</p> Signup and view all the answers

A superclass object is a subclass object.

<p>False</p> Signup and view all the answers

Which of the following is not a superclass/subclass relationship?

<p>Both</p> Signup and view all the answers

An advantage of inheritance is that?

<p>objects of a subclass can be treated like objects of their superclass.</p> Signup and view all the answers

Using the protected keyword gives a member?

<p>package access</p> Signup and view all the answers

To avoid duplicating code, use ________, rather than ________.

<p>False</p> Signup and view all the answers

Which of the following statements describes the state of instance variables after the constructor for class B executes?

<p>variable a will have the value 7 and variable b will have the value 8.</p> Signup and view all the answers

Which superclass members are inherited by all subclasses of that superclass?

<p>protected instance variables and methods.</p> 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?

<p>infinite recursion</p> 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?

<p>the program compiles and runs because the instance variables are initialized to their default values.</p> 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?

<p>All animals lay eggs, except for mammals.</p> Signup and view all the answers

The default implementation of method clone of Object performs a?

<p>shallow copy.</p> Signup and view all the answers

The default equals implementation determines?

<p>whether two references refer to the same object in memory.</p> Signup and view all the answers

Class ________ represents an image that can be displayed on a JLabel.

<p>ImageIcon</p> Signup and view all the answers

Which method changes the text the label displays?

<p>setText</p> Signup and view all the answers

Polymorphism enables you to?

<p>program in the general.</p> Signup and view all the answers

If the superclass contains only abstract method declarations, the superclass is used for?

<p>interface inheritance.</p> Signup and view all the answers

Answer by choosing the correct set of true statements:

<p>The purpose of an abstract class is to provide an appropriate superclass.</p> Signup and view all the answers

Which of the following does not complete the sentence correctly? An interface

<p>False</p> Signup and view all the answers

Classes and methods are declared final for all but the following reasons:

<p>final methods are static.</p> Signup and view all the answers

Classes from which objects can be instantiated are called?

<p>concrete classes.</p> Signup and view all the answers

Assigning a subclass reference to a superclass variable is safe.

<p>True</p> Signup and view all the answers

If a class contains at least one abstract method, it's a(n) ___________ class.

<p>abstract</p> Signup and view all the answers

For which of the following would polymorphism not provide a clean solution?

<p>A program to compute a 5% savings account interest for a variety of clients.</p> Signup and view all the answers

All methods in an abstract class must be declared as abstract methods.

<p>False</p> Signup and view all the answers

Which of the following statements about abstract superclasses is true?

<p>False</p> Signup and view all the answers

An interface may contain?

<p>public static final data and public abstract methods.</p> 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.

<p>True</p> Signup and view all the answers

Which of the following statements about interfaces is false?

<p>False</p> Signup and view all the answers

Which statement best describes the relationship between superclass and subclass types?

<p>A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.</p> Signup and view all the answers

Non-abstract classes are called:

<p>concrete classes.</p> 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?

<p>None of the above.</p> 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.

<p>True</p> Signup and view all the answers

Polymorphism allows for specifics to be dealt with during?

<p>execution.</p> 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:

<p>Both (a) and (b).</p> Signup and view all the answers

Which keyword is used to specify that a class will define the methods of an interface?

<p>implements.</p> Signup and view all the answers

All of the following methods are implicitly final except:

<p>a method in an abstract class.</p> Signup and view all the answers

This type of class cannot be a superclass.

<p>final</p> Signup and view all the answers

It is a UML convention to denote the name of an abstract class in?

<p>italics.</p> Signup and view all the answers

A(n) class cannot be instantiated.

<p>abstract.</p> 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)?

<p>public abstract int method1();</p> 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?

<p>execution time.</p> Signup and view all the answers

Every object in Java knows its own class and can access this information through the method?

<p>getClass.</p> Signup and view all the answers

Declaring a method final means?

<p>False</p> Signup and view all the answers

The UML distinguishes an interface from other classes by placing the word 'interface' in?

<p>guillemets.</p> Signup and view all the answers

Interfaces can have methods.

<p>True</p> Signup and view all the answers

Which of the following is not possible?

<p>A class that inherits from two classes.</p> 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?

<p>abstract.</p> Signup and view all the answers

Constants declared in an interface are implicitly?

<p>False</p> Signup and view all the answers

In a class diagram, properties may be related to the instance variables of a class.

<p>True</p> 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.

<p>True</p> Signup and view all the answers

Which of the following statements describe the type(s) of relationships that may be described by class diagrams?

<p>Only static relationships can be defined by class diagrams.</p> Signup and view all the answers

Operations in a class diagram correspond to _____ in Java.

<p>methods.</p> Signup and view all the answers

The proper way to indicate that a class property may have no value entered into it is ____________.

<p>to use a lower bound of zero.</p> Signup and view all the answers

Which of the following may be represented in a class diagram?

<p>All of the above.</p> Signup and view all the answers

The UML syntax for operations includes which of the following:

<p>Both A and B.</p> Signup and view all the answers

The features of a class can refer to both properties and operations.

<p>True</p> Signup and view all the answers

Which of the following may be found in an attribute notation (select all that apply)?

<p>Type</p> Signup and view all the answers

Whether an operation is public or private is indicated by either + for private or - for public.

<p>False</p> Signup and view all the answers

Something a business must track or that participates in the business may generally be called?

<p>a business object.</p> Signup and view all the answers

Which of the following should be visible to other objects?

<p>Operations.</p> Signup and view all the answers

Another way to talk about a superclass is?

<p>Parent.</p> Signup and view all the answers

The acronym OMG (when discussing UML) stands for which of the following?

<p>Object Management Group.</p> Signup and view all the answers

Polymorphism refers to the ability of _________ to take many 'shapes'.

<p>objects &amp; operations.</p> Signup and view all the answers

A subclass may add attributes, operations, and relationships to those inherited from the superclass.

<p>True</p> Signup and view all the answers

Polymorphism allows a subclass to override operations of a superclass, thus specializing the operation for the subclass.

<p>True</p> Signup and view all the answers

The UML standard is owned by which of the following?

<p>OMG.</p> Signup and view all the answers

An object of a subclass automatically?

<p>inherits all the attributes and operations of its superclass.</p> Signup and view all the answers

If two objects belong to the same class, which of the following statements about those objects is true?

<p>The procedure for carrying out a specific operation will be the same for both objects.</p> 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 ________.

<p>Polymorphism.</p> Signup and view all the answers

A 'method' is?

<p>an operation.</p> Signup and view all the answers

Two things that must be remembered about specific objects are (select two):

<p>Values of an object's attributes.</p> Signup and view all the answers

The ways objects may be related are?

<p>Association, Aggregation, Composition.</p> Signup and view all the answers

Attributes and operations defined at the class level will be shared by all objects of that class.

<p>True</p> 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.

Quiz Team

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.

More Like This

Use Quizgecko on...
Browser
Browser