Which of the following is the correct syntax for class B to inherit from class A? Question 2Answer a. public class A extends B b. public class B inherits A c. public class B extends A d. public class A inherits B
Added by Rosario K.
Step 1
Inheritance allows one class (the child or subclass) to inherit properties and methods from another class (the parent or superclass). Show more…
Show all steps
Your feedback will help us improve your experience
Sanchit Jain and 97 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Which of the following is the correct syntax to indicate that class A is a subclass of B? a. public class B extends A { b. public class A : super B { c. public A(super B) { d. public class A extends B { e. public A implements B {
Sanchit J.
Question 8(Multiple Choice Worth 2 points) Consider the following code: public class A1 { public int x; private int y; … } public class A2 extends A1 { public int a; private int b; … } public class A3 extends A2 { private int q; … } Which of the following sets of instance variables are directly accessible in class A2? a, b x, a, b x, y, a, b x, y, a, b, q y, a, b
James K.
Given the following Java code, what method m will be executed when b.m() is executed.. class A { void m() {..} } class B extends A {void m() {..} } class Client { public static void main (String args[]) { A a = new A(); B b = new B(); b.m(); }} a. Method m belonging to class B will be executed. b. Since B is a sub-class A, method m belonging to class B will be executed after method m belong to class A is executed. Super class methods are always executed first. c. Since B is a sub-class A, method m belonging to class A will be executed after method m belong to class B is executed. Sub class methods are always executed first. d. All other answers are wrong
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD