小编Mds*_*dsm的帖子

新的Obj,总是或有时候?

即使我知道我只会使用一个新的对象,我是否总是用java中的所有内容创建新对象?

 obj = new obj();
 obj.method();
Run Code Online (Sandbox Code Playgroud)

要不就

classOfobject.method(); 
Run Code Online (Sandbox Code Playgroud)

在这样的情况下,为什么我要为创建一个新的obj而烦恼呢?

java oop

0
推荐指数
1
解决办法
49
查看次数

C#接口和类继承

我在我的对象中使用接口方法时遇到问题.我是一个快速的例子,没有所有的补充.

public class Item{}
public interface IFruit
{
      void MethodExample();
}

public class Apple : Item, IFruit
{
    public void IFruit.MethodExample(){}
}

// put this in a run method somewhere
var example_item = new Apple();

//Here comes the problem.
example_item.MethodExample();
// this will return an error saying that it cant find the method.
Run Code Online (Sandbox Code Playgroud)

无论如何要做到这一点?我知道它实现了i_fruit.并有方法.但我无法访问它?

c# inheritance interface object

-2
推荐指数
1
解决办法
74
查看次数

标签 统计

c# ×1

inheritance ×1

interface ×1

java ×1

object ×1

oop ×1