File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes newbie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "newbie question" Watch "newbie question" New topic
Author

newbie question

salvador rcn
Ranch Hand

Joined: Feb 18, 2004
Posts: 51
hi , i am a newbie...i have some simple question


question... i am not comfortable with the syntax
outer.this.setValue(newOther);...is this legal? does it have any diffrence with outer.setValue(newOther); ?
another question..
class C {
class D {
}
}
C c = new C() //ok
D d = c.new D()---->how this works...this syntax is not understandable.

an object c is dotting(.)with other object new D() !! its surprising to me bcoz object creation rule is
classname objectname = new classname() right?
but that is not obeying this rule!
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

The questions u faced are really very common for programmers. There may be many other ways to solve your problems. But, I have some solutions.
Sol 1.
The syntax you gave is illegal. And I suggest to use 'super' keyword by extending your inner class to outer and then access 'super.setValue(Object obj).
Sol 2.
Since the class D is inner to C, D is local only to C. So, u can't create object in the main method directly. You follow this.
1. Create Object for class C. // C c=new C()
2. Get the object of the inner class. //c.new D()
3. If you want to assign the above to a particular object, then define like this(Since Object is the super class of all classes). // Object ob=c.new D()


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

The questions u faced are really very common for programmers. There may be many other ways to solve your problems. But, I have some solutions.
Sol 1.
The syntax you gave is illegal. And I suggest to use 'super' keyword by extending your inner class to outer and then access 'super.setValue(Object obj).
Sol 2.
Since the class D is inner to C, D is local only to C. So, u can't create object in the main method directly. You follow this.
1. Create Object for class C. // C c=new C()
2. Get the object of the inner class. //c.new D()
3. If you want to assign the above to a particular object, then define like this(Since Object is the super class of all classes). // Object ob=c.new D()
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

The solution I gave for 2nd question may confuse you. You can get access to the member in inner class by writing 'c.new D().member'.
If you want to assign the above it to a particular object, u declare like this.
C.D obj=c.new D(); // outerCLASS.innerCLASS innerOBJECT= outerOBJECT.new innerCLASS()
And you can access the inner member by obj.member
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
ssrc,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You might want to take a look at the "Getting in Touch with your Inner Class" article of the JavaRanch Campfire Stories.
 
Don't get me started about those stupid light bulbs.
 
subject: newbie question