Click here to Skip to main content
16,013,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Object and reference In the example:

SomeObject aRef = new SomeObject(); In this example which one object and reference....
Posted

aRef is a valid reference to the object created with SomeObject() constructor.
 
Share this answer
 
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.
 
Share this answer
 
Java
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
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900