【发布时间】:2014-05-12 06:18:21
【问题描述】:
我有这样的程序代码。
我的界面是
public interface MyInterface {
public void m1(String name);
public void m2(int num);
}
我有一个实现上述接口的类。
public class World implements MyInterface {
public void m1(String name) {
System.out.println(name);
}
public void m2(int num){
System.out.println("Number is: "+num);
}
public static void main(String args[]) {
MyInterface ob1 = new World(); //How it is instantiated
MyInterface ob2 = new World(); //How this one too is instantiated
ob1.m1("Jaguar");
ob2.m2(5);
}
}
【问题讨论】:
-
你能说得清楚点吗?
-
我不确定你对那个代码有什么困惑...
-
@Gliptal 我在问一个对象是如何被类构造函数实例化的。但后来我得到了我的答案,它是通过实例化类来分配的。
-
@OliCharlesworth 以上是对您评论的回复。
标签: java interface constructor instantiation