对象和参考在示例中 [英] Object and reference In the example
本文介绍了对象和参考在示例中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对象和引用在示例中:
SomeObject aRef = new SomeObject();在此示例中,哪个对象和引用....
Object and reference In the example:
SomeObject aRef = new SomeObject(); In this example which one object and reference....
推荐答案
aRef
是对使用SomeObject()
构造函数创建的对象的有效引用.
aRef
is a valid reference to the object created withSomeObject()
constructor.
这里,aRef不是对象,它是一个包含对对象的引用的变量.对象没有名称,只是内存中的类型和位置(当然还有字段和方法).读取以下语句:在内存中创建一个新的SomeObject对象,使用作为构造函数的参数发送的数据对其进行初始化,并在创建时将对该对象的引用分配给SomeObject变量aRef. aRef是引用或对象类型变量,可以引用SomeObject对象或SomeObject的任何子类的对象.
Here, aRef is not an object, it''s a variable which contains a reference to an object. Objects don''t have names, just types and locations in memory (and, of course,fields and methods). Read your statement as: Create a new SomeObject object in memory, initializing it with the data sent as arguments to a constructor, and when created, assign a reference to that object to the SomeObject variable aRef. aRef is a reference or object type variable which may reference a SomeObject object or an object of any subclass of SomeObject.
Using anonymous Inner class concept we can create an object for an interface…..
Here is a sample code
interface Sample {
public void method();
}
class Outer {
Sample s = new Sample() {
public void method() {
System.out.println("Inner class");
}
};
}
public class Example {
public static void main(String args[]) {
Outer o = new Outer();
o.s.method();
}
}
Output: Inner class
这篇关于对象和参考在示例中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文