Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following code, which of the following is the correct definition for class B, such that the output of the program is 1 2

Given the following code, which of the following is the correct definition for class B, such that the output of the program is 1 2 3 : [Hint: Pay close attention to the Access Modifiers]

Java

C#

public class A {

private int x;

private int y;

public A(int a, int b) {

x=a;

y=b;

}

@Override

public String toString() {

return x+" "+y;

}

}

//Class B goes here.

class Main {

public static void main(String[] args) {

B myB=new B(1,2,3);

System.out.println(myB);

}

}

public class A { private int x; private int y;

public A(int a, int b) { x=a; y=b; }

public override string ToString() { return x+" "+y; } }

//Class B goes here

class MainClass {

public static void Main (string[] args) {

B myB=new B(1,2,3);

Console.WriteLine(myB);

}

}

Question 3 options:

class B extends A {

private int z;

public B(int a, int b, int c) {

super(a,b);

z=c;

}

@Override

public String toString() {

return x+" "+y+" "+z;

}

}

class B : A {

private int z;

public B(int a, int b, int c) : base(a,b) {

z=c;

}

public override string ToString() {

return x+" "+y+" "+z;

}

}

class B extends A {

private int z;

public B(int a, int b, int c) {

super(a,b);

z=c;

}

@Override

public String toString() {

return super.toString()+" "+z;

}

}

class B : A {

private int z;

public B(int a, int b, int c) : base(a,b) {

z=c;

}

public override string ToString() {

return base.ToString()+" "+z;

}

}

class B extends A {

private int z;

public B(int a, int b, int c) {

super(a,b);

z=c;

}

@Override

public String toString() {

return super()+" "+z;

}

}

class B : A {

private int z;

public B(int a, int b, int c) : base(a,b) {

z=c;

}

public override string ToString() {

return base()+" "+z;

}

}

class B extends A {

private int z;

public B(int a, int b, int c) {

super(a,b);

z=c;

}

@Override

public String toString() {

return super.x+" "+super.y+" "+z;

}

}

class B : A {

private int z;

public B(int a, int b, int c) : base(a,b) {

z=c;

}

public override string ToString() {

return base.x+" "+base.y+" "+z;

}

}

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions