Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1 Inhertiance21 PointsGrading comment: For each of the following, tell if the code will compile. If so, what will be be printed? If not, why

Q1 Inhertiance21 PointsGrading comment:

For each of the following, tell if the code will compile. If so, what will be be printed? If not, why will it not compile?

Give a one sentence reasoning for EITHER outcome. (No reasoning gets max 1 point.) Note: Syntax errors, if any, are inadvertent and should be ignored. Also, code outside of an explicit class is considered to be in the main method of some arbitrary class in the same package. (Fields that are not private are accessible to all classes in same package.)

Q1.44 PointsGrading comment:

public class X { public int x=2; public int getX() { return x; } public String toString() { return x + ""; } } public class Y extends X { public int y=3; public String toString() { return (getX() + y) + ""; } } X x = new Y(); System.out.println(x);

Q1.54 PointsGrading comment:

public class A { public int x; public A(int x) { this.x = x; } } public class B extends A { public static void main(String[] args) { System.out.println("B"); } }

Q1.63 PointsGrading comment:

public class M { public static int mn=2; } public class N extends M { public int mn; } M m = new N(); System.out.println(m.mn);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Business Statistics

Authors: Andrew Siegel

6th Edition

0123852080, 978-0123852083

More Books

Students also viewed these Programming questions

Question

Are you at your best around 8 or 9 AM? Yes No

Answered: 1 week ago