Question
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:
| |||
| |||
| |||
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started