Inheritance and Abstract

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Suppose A is an interface, B is a concrete class with a no-arg constructor that implements A. Which of the following is correct? A. A a = new A(); B. A a = new B(); C. B b = new A(); D. B b = new B();

A a = new B(); B b = new B(); Since B is a concrete class with a no-arg constructor, d is correct. Since an instance of B is also an instance of A, b is also correct.

_______ is not a reference type.

A primitive type

Which of the following statements are true? A. A subclass is a subset of a superclass. B. A subclass is usually extended to contain more functions and more detailed information than its superclass. C. "class A extends B" means A is a subclass of B. D. "class A extends B" means B is a subclass of A.

A subclass is usually extended to contain more functions and more detailed information than its superclass. "class A extends B" means A is a subclass of B.

Which of the following statements are true? A. Inheritance models the is-a relationship between two classes. B. A strong is-a relationship describes a direct inheritance relationship between two classes. C. A weak is-a relationship describes that a class has certain properties. D. A strong is-a relationship can be represented using class inheritance. E. A weak is-a relationship can be represented using interfaces.

All of them are true

Which of the following are incorrect? A. An abstract class contains constructors. B. The constructors in an abstract class should be protected. C. The constructors in an abstract class are private. D. You may declare a final abstract class. E. An interface may contain constructors.

C. The constructors in an abstract class are private. D. You may declare a final abstract class. E. An interface may contain constructors.

Assume an employee can work for only one company. What is the best suitable relationship between Company and Employee?

Composition

How many types of inheritance exists?

Five Single Multilevel Hierarchical Multiple and Hybrid

Which of the following statements is false? A. If you compile an interface without errors, a .class file is created for the interface. B. If you compile a class without errors but with warnings, a .class file is created. C. If you compile a class with errors, a .class file is created for the class. D. If you compile an interface without errors, but with warnings, a .class file is created for the interface.

If you compile a class with errors, a .class file is created for the class. A .class file is created for each Java class and interface. But if it has a compile error, no .class file is created.

The relationship between an interface and the class that implements it is

Inheritance

What is the best suitable relationship between Employee and Faculty?

Inheritance

How many types of inheritance exists and why in regards to Abstract class vs interface would we use one or the other?

Since java does not support multiple inheritances in the case of class, by using an interface it can achieve multiple inheritances.

Which of the statements regarding the super keyword is incorrect? A. You can use super to invoke a super class constructor. B. You can use super to invoke a super class method. C. You can use super.super.p to invoke a method in superclass's parent class. D. You cannot invoke a method in superclass's parent class.

You can use super.super.p to invoke a method in superclass's parent class.

Object-oriented programming allows you to derive new classes from existing classes. This is called ____________.

inheritance

Which of the following is a correct interface? A. interface A { void print() { }; } B. abstract interface A { print(); } C. abstract interface A { abstract void print() { };} D. interface A { void print();}

interface A { void print();} In A, the print() method in the interface is a concrete method. In B and C, the abstract keyword is used before the interface, which is wrong.

Inheritance means ______________. A. that data fields should be declared private B. that a class can extend another class C. that a variable of supertype can refer to a subtype object D. that a class can contain another class

that a class can extend another class

Composition means ______________. A. that data fields should be declared private B. that a class extends another class C. that a variable of supertype refers to a subtype object D. that a class contains a data field that references another object

that a class contains a data field that references another object

Polymorphism means ______________. A. that data fields should be declared private B. that a class can extend another class C. that a variable of supertype can refer to a subtype object D. that a class can contain another class

that a variable of supertype can refer to a subtype object

Encapsulation means ______________. A. that data fields should be declared private B. that a class can extend another class C. that a variable of supertype can refer to a subtype object D. that a class can contain another class

that data fields should be declared private


Ensembles d'études connexes

The Skeletal and muscle system

View Set

Culinary Safe Staff 81 Questions

View Set

Comps: Complete Terms Practice Sets

View Set

Microeconomics final study guide

View Set