BUG: Cannot Override Abstract Class Member When You Convert Your Code to C# (821176)



The information in this article applies to:

  • Microsoft Visual J++ 1.0
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

SYMPTOMS

You can use the Java Language Conversion Assistant (JLCA) to convert a project that is written in the Java programming language or the Visual J++ programming language to the C# programming language. However, when you convert Java code that has an abstract method that is defined in an abstract class, and this method is overridden in a derived class, you may receive the following error message when you compile the C# code:
Cannot change access modifiers when overriding 'internal' inherited member

CAUSE

This problem occurs because the JLCA adds an internal modifier for the abstract method in the abstract class when JCLA converts the Java code.

RESOLUTION

To resolve this problem, edit the C# code that the JLCA generates. Replace the internal modifier with a public modifier. The following is the modified code:
abstract class Bird
{
	public abstract void  Wings();
}

class Robin:Bird
{
	public override void  Wings()
	{
		System.Console.Out.WriteLine("Robin");
	}
}

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start a text editor such as Notepad, and then paste the following code in a new document:
    abstract class Bird {
      abstract void Wings();
    }
    
    class Robin extends Bird {
      public void Wings() { 
        System.out.println("Robin"); 
      }
    }
    
  2. Save the file as c:\Sample.java, and then quit the text editor.
  3. At a command prompt, type the following command, and then press ENTER:

    Microsoft Visual Studio .NET Setup Path\JavaLanguageConversionAssistantJConvert C:\Sample.java

    The Sample.cs file and other project files are created.
  4. In Visual Studio .NET, open the project that you created in steps 1 through 3.
  5. On the Build menu, click Build Solution.

Modification Type:MinorLast Reviewed:8/15/2005
Keywords:kbpending kbCodeGen kbJava kbbug KB821176 kbAudDeveloper kbAudITPRO