Ask Question
26 May, 08:50

What is wrong with the following program and how should it be fixed?

1 public class MyClassD {

2 public static void main (String args []) {

3 MyClassC m = new MyClassC (23);

4 } / / end main

5 } / / end class MyClassD

+1
Answers (1)
  1. 26 May, 12:33
    0
    Their is no MyClassC class is found in the code.

    The correct code for the given question isto create a MyClassC class with parameterized constructor.

    The code is given below

    public class MyClassC

    {

    int p;

    public MyClassC (int v) / / hold the integer value

    {

    p=v;

    }

    }/ / end class MyClassc

    Explanation:

    According to the code as given in the question in the main method it will call parametrized constructor of MyClassC but their is no such kind of class be there so we will create a class MyClassC and also create a parametrized constructor with integer parameter.

    The final correct program is given below.

    public class MyClassC / / class

    {

    int p;

    public MyClassC (int v)

    {

    p=v;

    }

    }/ / end class MyClassC

    public class MyClassD

    {

    public static void main (String args []) / / main method

    {

    MyClassC m = new MyClassC (23); / / call the parametrized constructor of class c

    } / / end main

    } / / end class MyClassD
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What is wrong with the following program and how should it be fixed? 1 public class MyClassD { 2 public static void main (String args []) { ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers