Select all correct answers (Hint: There are two) (Gamma) var2.method3() will invoke method3() from the Gamma class. O (Delta)var2.method3() will print Delta 2 and Delta 3. O (Delta)var2.method3() will cause a casting error. O (Gamma) var2.method3() will cause a casting error.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Java
public class Gamma extends Be
ta {
public void method1() {
System.out.println("G
amma 1");
super.method2);
public class Alpha {
public void method1() {
System.out.println("A
public void method3() {
System.out.println("G
Lpha 1");
amma 3");
}
public void method2() {
System.out.println("A
public class Beta extends Alp
ha {
public void method2() {
System.out.println("B
lpha 2");
}
eta 2");
And assuming the following
super.method2();
}
}
variables have been defined:
public class Delta extends Be
ta {
public void method2() {
System.out.println("De
Alpha var1 = new Gamma();
new Delta();
Alpha var3 = new Beta();
Object var4 = new Beta();
Beta var2
lta 2");
}
Answer Inheritance Q1 - Q3
below:
public void method3() {
method2();
System.out,println("De
lta 3");
}
}
Transcribed Image Text:public class Gamma extends Be ta { public void method1() { System.out.println("G amma 1"); super.method2); public class Alpha { public void method1() { System.out.println("A public void method3() { System.out.println("G Lpha 1"); amma 3"); } public void method2() { System.out.println("A public class Beta extends Alp ha { public void method2() { System.out.println("B lpha 2"); } eta 2"); And assuming the following super.method2(); } } variables have been defined: public class Delta extends Be ta { public void method2() { System.out.println("De Alpha var1 = new Gamma(); new Delta(); Alpha var3 = new Beta(); Object var4 = new Beta(); Beta var2 lta 2"); } Answer Inheritance Q1 - Q3 below: public void method3() { method2(); System.out,println("De lta 3"); } }
Select all correct answers (Hint: There are two)
(Gamma) var2.method3() will invoke method3() from the Gamma class.
O (Delta)var2.method3() will print Delta 2 and Delta 3.
O (Delta)var2.method3() will cause a casting error.
O (Gamma) var2.method3() will cause a casting error.
Transcribed Image Text:Select all correct answers (Hint: There are two) (Gamma) var2.method3() will invoke method3() from the Gamma class. O (Delta)var2.method3() will print Delta 2 and Delta 3. O (Delta)var2.method3() will cause a casting error. O (Gamma) var2.method3() will cause a casting error.
Expert Solution
Answer & Explanation of option 1:

Correct options are :

2 and 4 

B and D.

 

Explanation of 1:

 

As Gamma extends Beta all the methods from Beta accessible to Gamma but not the same case for Beta So if we consider m3() is accessible from Beta class then It will invoke method m3() from Gamma class.

 

So the problem remains is about casting.

In this case we are trying to Cast Delta class to Gamma class which will give rise to Exception name as ClassCastException hence this is incorrect.

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education