Ask Question
2 September, 18:46

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

+4
Answers (1)
  1. 2 September, 19:46
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers