100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Chapter 11 Inheritance and Polymorphism UPDATED ACTUAL Questions and CORRECT Answers $10.99   Add to cart

Exam (elaborations)

Chapter 11 Inheritance and Polymorphism UPDATED ACTUAL Questions and CORRECT Answers

 0 view  0 purchase
  • Course
  • Inheritance and Polymorphism
  • Institution
  • Inheritance And Polymorphism

Chapter 11 Inheritance and Polymorphism UPDATED ACTUAL Questions and CORRECT Answers Object-oriented programming allows you to derive new classes from existing classes. This is called ____________. A. encapsulation B. inheritance C. abstraction D. generalization - CORRECT ANSWER- B. inher...

[Show more]

Preview 3 out of 26  pages

  • November 18, 2024
  • 26
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • Inheritance and Polymorphism
  • Inheritance and Polymorphism
avatar-seller
MGRADES
Chapter 11 Inheritance and Polymorphism
UPDATED ACTUAL Questions and
CORRECT Answers
Object-oriented programming allows you to derive new classes from existing classes. This is
called ____________.
A. encapsulation
B. inheritance
C. abstraction

D. generalization - CORRECT ANSWER✔✔- B. inheritance


Suppose you create a class Square to be a subclass of GeometricObject. Analyze the
following code:


class Square extends GeometricObject {
double length;


Square(double length) {
GeometricObject(length);
}

} - CORRECT ANSWER✔✔- B. The program has a compile error because you attempted to
invoke the GeometricObject class's constructor illegally.


11.6 What is the output of running class C?


class A {
public A() {
System.out.println(
"The default constructor of A is invoked");
}
}

,class B extends A {
public B() {
System.out.println(
"The default constructor of B is invoked");
}
}


public class C {
public static void main(String[] args) {
B b = new B();
}

} - CORRECT ANSWER✔✔- C. "The default constructor of A is invoked" followed by
"The default constructor of B is invoked"


11.7 Which of the following is incorrect?
A. A constructor may be static.
B. A constructor may be private.
C. A constructor may invoke a static method.
D. A constructor may invoke an overloaded constructor.
E. A constructor invokes its superclass no-arg constructor by default if a constructor does not
invoke an overloaded constructor or its superclass?s constructor. - CORRECT ANSWER✔✔-
A. A constructor may be static.


11.8 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. - CORRECT ANSWER✔✔- C.
You can use super.super.p to invoke a method in superclass's parent class.

, 11.9 Analyze the following code:


public class Test {
public static void main(String[] args) {
B b = new B();
b.m(5);
System.out.println("i is " + b.i);
}
}


class A {
int i;


public void m(int i) {
this.i = i;
}
}


class B extends A {
public void m(String s) {
}
}
A. The program has a compile error, because m is overridden with a different signature in B.
B. The program has a compile error, because b.m(5) cannot be invoked since the method
m(int) is hidden in B.
C. The program has a runtime error on b.i, because i is not accessible from b.
D. The method m is not overridden in B. B inherits the method m from A and defines an
overloaded method m in B. - CORRECT ANSWER✔✔- D. The method m is not overridden
in B. B inherits the method m from A and defines an overloaded method m in B.


11.10 The getValue() method is overridden in two ways. Which one is correct?

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller MGRADES. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $10.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67163 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$10.99
  • (0)
  Add to cart