public class Parent { void printMe() { System.out.println("parent"); } } class Child extends Parent { void printMe() { System.out.println("child"); } void printAll() { super.printMe(); this.printMe(); } } public class Examae { public static void main(String args[]) { (new Child()).printAll(); System.out.println("grandson"); } },将这串Java代码转化为C#d
时间: 2023-11-28 11:48:17 浏览: 101
以下是将 Java 代码转化为 C# 代码的结果:
```csharp
using System;
public class Parent
{
public void printMe()
{
Console.WriteLine("parent");
}
}
public class Child : Parent
{
public void printMe()
{
Console.WriteLine("child");
}
public void printAll()
{
base.printMe();
this.printMe();
}
}
public class Example
{
public static void Main(string[] args)
{
(new Child()).printAll();
Console.WriteLine("grandson");
}
}
```
相关问题
public class Parent { void printMe() { System.out.println("parent"); } } class Child extends Parent { void printMe() { System.out.println("child"); } void printAll() { super.printMe(); this.printMe(); } } public class Examae { public static void main(String args[]) { (new Child()).printAll(); System.out.println("grandson"); } }转换为C#
以下是转换后的 C# 代码:
```
using System;
public class Parent
{
public virtual void PrintMe()
{
Console.WriteLine("parent");
}
}
public class Child : Parent
{
public override void PrintMe()
{
Console.WriteLine("child");
}
public void PrintAll()
{
base.PrintMe();
this.PrintMe();
}
}
public class Example
{
public static void Main()
{
(new Child()).PrintAll();
Console.WriteLine("grandson");
}
}
```
public class Parent { void printMe() { System.out.println("parent"); } } class Child extends Parent { void printMe() { System.out.println("child"); } void printAll() { super.printMe(); this.printMe(); } } public class Examae { public static void main(String args[]) { (new Child()).printAll(); System.out.println("grandson"); } }转换为C#网页输出
Sorry,我之前理解错了你的意思,我无法将Java代码转换为C#网页输出。不过,你可以手动将上述Java代码转换为C#代码并在网页上输出,下面是转换后的C#代码:
```csharp
using System;
class Parent {
public void PrintMe() {
Console.WriteLine("parent");
}
}
class Child : Parent {
public void PrintMe() {
Console.WriteLine("child");
}
public void PrintAll() {
base.PrintMe();
this.PrintMe();
}
}
class Examae {
static void Main(string[] args) {
(new Child()).PrintAll();
Console.WriteLine("grandson");
}
}
```
请注意,C#中的类和方法名称应该以大写字母开头,并且在调用基类方法时使用关键字`base`而不是`super`。
阅读全文