Ask 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 []) {

3 MyClassC m = new MyClassC (23);

4 } / / end main

5 } / / end class MyClassD

+1
Answers (1)
  1. 7 May, 15:38
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers