Object Oriented Programming - Exam 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

B. False

An abstract class must be declared abstract and all of its methods must be declared abstract as well. a. True b. False

B. False

An abstract class must include abstract methods. a. True b. False

D. A, B, and C

An abstract method is a method that is: a. Declared without implementation b. Has no curly braces c. Ends with a semicolon d. A, B, and C e. None of the above

B. False

An interface can and should be instantiated. a. True b. False

A. True

Classes can be declared as final. a. True b. False

C. Abstract classes

Classes that cannot have objects created from them are called __________ a. interfaces b. superclasses c. abstract classes d. subclasses

A. Abstract

Classes that cannot have objects created from them are called what? a. Abstract b. Concrete c. Interfaces d. Inheritance e. Polymorphism

A. public B. package-private C. private D. protected

Define the following: a. _____: visible to all classes everywhere b. _____: visible only within its own package c. _____: can only be accessed in its own class d. _____: can only be accessed within its own package; can be accessed by a subclass of it class in another package

B. in a constructor use this to call another constructor in the same class

Explicit constructor invocation refers to what OOP practice? a. to call the superclass's constructor b. in a constructor use this to call another constructor in the same class c. to call the abstract class's constructor d. to call the subclass's constructor

A. True

Interface can be implemented by other classes. a. True b. False

B. False

Interface can be instantiated. a. True b. False

B. False

Interfaces and abstract classes can have objects instantiated from them. a. True b. False

A, C, D, F, G

Interfaces can contain only the following. Select all that apply. a. method signatures b. method bodies other than default or static c. default methods d. static methods e. member variables f. nested types g. constants

B. False

Interfaces cannot be extend by other interfaces. a. True b. False

B. The ability to inherit method definitions from multiple classes

Multiple inheritance of implementation in polymorphism refers to what situation in object oriented programming? a. The ability to inherit fields from multiple classes b. The ability to inherit method definitions from multiple classes c. The ability to implement more than one interface The ability to inherit constants from multiple static classes

A. The ability to inherit fields from multiple classes

Multiple inheritance of state in polymorphism refers to what situation in object oriented programming? a. The ability to inherit fields from multiple classes b. The ability to inherit method definitions from multiple classes c. The ability to implement more than one interface d. The ability to inherit constants from multiple static classes

C. A and B

Multiple inheritance of type in polymorphism refers to what situation in object oriented programming? a. A class can implement more than one interface b. An object can have multiple types c. A and B d. None of the above

B. False

Polymorphism in the Java programming language allows for extending multiple superclasses. a. True b. False

A. True

Polymorphism refers to a principle in biology in which an organism or species can have many different forms or stages a. True b. False

B. visible only within its own package

Regarding access level modifiers, what does package-private mean? a. visible to all classes everywhere b. visible only within its own package c. can only be accessed in its own class d. can only be accessed within its own package e. can be accessed by a subclass of its class in another package

C. can only be accessed in its own class

Regarding access level modifiers, what does private mean? a. visible to all classes everywhere b. visible only within its own package c. can only be accessed in its own class d. can only be accessed within its own package e. can be accessed by a subclass of its class in another package

A. visible to all classes everywhere

Regarding access level modifiers, what does public mean? a. visible to all classes everywhere b. visible only within its own package c. can only be accessed in its own class d. can only be accessed within its own package e. can be accessed by a subclass of its class in another package

A. encounters a continue statement

Regarding methods of classes, which of the following is NOT one of the the three ways a method returns to the code that invoked it? a. encounters a continue statement b. reaches a return statement c. throws an exception d. completes all the statements in the method

A, C, D, E, F

Regarding the return type of a method, which of the following would be valid? Check all that apply. a. void b. leave it empty (e.g. public setData(int data)) c. class d. primitive data type (e.g. int, float, boolean) e. a subclass of the specified class return type f. interface

A. True

Returning a value from a method that is declared as void would result in a compiler error. a. True b. False

C. class variables

Static fields in a class are also know as __________. a. member variables b. instance variables c. class variables d. constants

D. The current object

The keyword this is used to reference __________. a. The inheritance b. The interface c. The subclass d. The current object e. The class's destructor

B. Concrete

The subclass of an abstract class that declares the missing pieces of the incomplete abstract class is called what? a. Abstract b. Concrete c. Interfaces d. Inheritance e. Polymorphism

A or B

To create a constant in a class, what is the correct implementation? a. public final static int NOON = 12; b. private final static int NOON = 12; c. public final int NOON = 12; d. public static int NOON = 12; e. private final int NOON = 12;

A. public static final int NOON = 12;

To create a constant, what is the correct implementation? a. public static final int NOON = 12; b. public final int NOON = 12; c. public static final NOON = 12; d. public static int NOON = 12;

A. True

Using the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses. a. True b. False

C. refer to a subclass of the class

Using the keyword this has multiple uses in OOP. Which of the following is NOT a correct usage? a. referencing the current object b. in a constructor use this to call another constructor in the same class c. refer to a subclass of the class d. field is shadowed by a method or constructor parameter

D. Method overloading

What allows for methods to have the same name but different method signatures in object oriented programming? a. Class overriding b. Method overriding c. Class overloading d. Method overloading e. Shadowing

D. Parameter list

What differentiates methods with the same name in a class? a. Return type b. Access modifier c. Argument list d. Parameter list e. None of the above, this is not permitted

A. They cannot be modified

What does the keyword final indicated regarding methods or field members of a class? a. They cannot be modified b. They are public c. They are private d. They are modifiable e. None of the above

A. Concrete Class

What is a subclass of an abstract superclass called that declares the missing pieces of the abstract class and can be instantiated? a. concrete class b. default class c. superclass d. fiberglass class

B. When a class implements one or more interfaces and may also extend a superclass

What is polymorphism in object-oriented programming? a. The same as inheritance with one or more super classes. b. When a class implements one or more interfaces and may also extend a superclass c. The same as implementing a single interface d. None of the above

B. Public

What is the automatic access modifier of methods and fields of interfaces? a. Package b. Public c. Package-private d. Private e. Protected

E. All instances created

When a class declares a member variable as static and there are 10 instances of that class created, which instance can modify the value of the static member variable? a. None b. The first instance created c. The last instance created d. The middle instance created e. All instances created

A. 1

When a class declares a member variable as static, how many instances of that static member variable exist if there are 10 objects of the class created? a. 1 b. 2 c. 5 d. 10 e. 20

B. Class variable

When a class declares a member variable using the keyword static, what is this also known as? a. Instance variable b. Class variable c. Project variable d. Package variable e. None of the above

A. True

When a class includes a method that is declared as static, the method can be accessed without creating an instance of the class. a. True b. False

B. False

When an abstract class is extended as a subclass, all abstract methods MUST implement the the abstract methods. a. True b. False

B, C, E

When deciding between an abstract class and an interface, which of the following would apply to selecting an interface? a. Want to share code among several closely related classes b. Want to take advantage of multiple inheritance of type c. Expect that unrelated classes would implement the interface d. This enables you to define methods that can access and modify the state of the object to which they belong e. Want to specify the behavior of a particular data type, but not concerned about who implements its behavior f. Want to declare non-static or non-final fields. g. Expect that classes that extend the abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private)

A, B, C, E

When deciding between an abstract class versus an interface, if selecting an abstract class which of the following apply? Select all that are applicable. a. want to share code among several closely related classes b. This enables you to define methods that can access and modify the state of the object to which they belong c. Expect that classes that extend the abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private) d. Want to specify the behavior of a particular data type, but not concerned about who implements its behavior e. Want to declare non-static or non-final fields. f. Expect that unrelated classes would implement the interface g. Want to take advantage of multiple inheritance of type

A. Package

When defining a method interface, it MUST be specified public, otherwise it is only accessible where in a project? a. package b. project c. any class in another package d. any class in any package of the project

E. A, B, or C

When does a method return to the code that invoked it? a. Completes all the statements in the method b. Reaches a return statement c. Throws an exception d. A or B e. A, B, or C

C. Subclasses can share some of the same behavior of the parent class but also can define their own unique behaviors

When polymorphism is applied to OOP it means that a. Subclasses MUST define their own unique behaviors of the superclass b. Subclasses MUST override constants of the parent class c. Subclasses can share some of the same behavior of the parent class but also can define their own unique behaviors d. Subclasses completely override their superclass behaviors

A. True

When using explicit contractor invocation the invocation of another constructor MUST be the first line in the constructor. a. True b. False

B. every instance of the class shares a class variable in one fixed location in memory

When using static fields in a class, how many instances of the field exists when creating a minimum of 10 objects of the class. a. half of the number of created objects (i.e. if 10 objects created, there are 5 of the static fields) b. every instance of the class shares a class variable in one fixed location in memory c. none d. the same number of created objects (i.e. if 10 objects are created then there are 10 instances of the static field)

B. Defining what the method should do when implemented

Which of the following is NOT a benefit of default methods in an interface? a. Adding new functionality to the existing interfaces b. Defining what the method should do when implemented c. specify the method definition in an interface is a default method with the default keyword at the beginning of the method signature d. Allows for binary compatibility with code written for older versions of those interfaces

D. There is always a single programmer who defines everything so they are in charge of the interfaces as well

Which of the following is NOT a reason to develop interfaces? a. Separate programmers or groups of programmers agree upon how their software will interact b. Each programmer or group develops their specific model independent of the other programmer or group c. No concern if the developed models will interact correctly since the programmers or groups defined ahead of time the interface d. There is always a single programmer who defines everything so they are in charge of the interfaces as well

B & D

Why do developers create abstract classes? Select all that apply. a. to avoid using superclasses b. to share a common design c. to create a unique class design d. to provide an appropriate superclass from which other classes can inherit

A. True

A class can have multiple constructors. a. True b. False

A. True

A class can have some or all of its methods declared as final. a. True b. False

B. False

A class that is declared final can be extended or subclassed. a. True b. False

B. False

A class that is declared final can be subclassed. a. True b. False

D. Class, interface

A method in object oriented programming can return primitive data types, __________, or __________. a. Project, package b. Function, method c. Constructor, exception d. Class, interface e. Code, return

A. True

A programmer can define a reference variable with an interface as its data type if the constructor call to the left of the equals sign (=) is a class instance that implements that interface. a. True b. False

B. Implementation

A subclass of an abstract class must provide _________ for all abstract methods of the superclass to be considered a concrete class. a. Interfaces b. Implementation c. Guidance d. Comments e. Shadowing

A. abstract superclasses

Abstract classes are used only as superclasses in inheritance hierarchies and are referred to as __________ a. abstract superclasses b. default classes c. subclasses d. superclassess

B. False

Abstract classes can be instantiated. a. True b. False

C. Abstract superclasses

Abstract classes used only in inheritance hierarchy and cannot be instantiate are referred to as what? a. Interfaces b. Superclasses c. Abstract superclasses d. Polymorphism e. Interference

B. False

Abstract methods, like default methods, included an implementation. a. True b. False

C. how other classes can reference a field or invoke a method

Access level modifiers define what? a. how to use the Java API b. how packages interact with each other c. how other classes can reference a field or invoke a method d. how projects interact with each other

B. False

Access level modifiers do not define how other classes can reference a field or invoke a method. a. True b. False

C. Package-private

1. If a class is declared without an access level modifier, what is the default modifier assigned? a. Public b. Private c. Package-private d. Protected e. Default

A. True

If a class implements an interface and extends a class, the resulting class can be an instance of: 1. The interface 2. The superclass 3. The subclass a. True b. False

B. Yes

If a class includes a static method, is it required to create an instance of the class to use the method? a. No b. Yes

B. False

If a method in a class is declared as final, a subclass of it can override the superclass's method and write its own implementation. a. True b. False

A. True

If a method is declared with a return type other than void, the method must return a value and the value must return an acceptable value relative to its declared return type (e.g. return type int can return the value of 0, return type boolean can return a value of true, return type of some class can return the value of null). a. True b. False

B. Anywhere in the body of the method

If a method is declared with a return type other than void, where in the method bocy is the data returned? a. Not required b. Anywhere in the body of the method c. Must be the very last statement d. Must the be the very first statement

A. True

If a subclass of an abstract class does not provide an implementation for all of the abstract methods it must be declared as abstract. a. True b. False

A. True

If an interface is declared public then a programmer can omit the public access modifier for all abstract, default, and static methods. a. True b. False

A, B, E, F

In a public interface body which of the following are automatically considered public even if the programmer doesn't put the public access modifier on the associated method or member? Select all that apply. a. Constant declarations b. default methods c. member variables d. method signatures e. static methods f. abstract methods


संबंधित स्टडी सेट्स

Intro til økonomi og det fri marked

View Set

ODPOWIEDZI - MOCK EXAM - wersja B - PROSZĘ SPRAWDZIĆ SWOJE ODPOWIEDZI!!!

View Set

CT Life and Health Exam Chapter 5

View Set

Business English: telephoning language

View Set

Psychology - Social, Retrieval Practice

View Set

Chapter 01: Taking a Computer Apart and Putting it Back Together- Quiz 1

View Set

Nursing Sciences EAQ, Theory Communication, Nursing SBU

View Set