aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need help on accessing the method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need help on accessing the method" Watch "Need help on accessing the method" New topic
Author

Need help on accessing the method

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486


Can anyone tell how to access the getPoint() method.
Please..
I think we can acess like this :
Line l = new Line();
l.getPoint();

Source is my own


Thanks<br />Dinesh
Matt Russell
Ranch Hand

Joined: Aug 15, 2006
Posts: 165
The following should do the trick:

The thing to know is that you need an instance of the outer class before you can create an instance of the inner class. (That's what the odd-looking "line.new Point()" syntax is all about.)


Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
I think we are accessing the inner class outside outer class.
Correct me if iam wrong..
Keith Nagle
Ranch Hand

Joined: May 06, 2008
Posts: 65
That's right.
Accessing the inner class outside of the enclosing class.


SCJP 5.0
Saurabh V Vakil
Greenhorn

Joined: Jan 30, 2008
Posts: 14
Originally posted by Dinesh Tahiliani:
I think we are accessing the inner class outside outer class.
Correct me if iam wrong..


you aren't accessing inner class(Point) outside outer class(Line) as main method is a part of the Line class.
you need an instance of class Point to access the getPoint() method, so l.getPoint() won't do since l is not an instance of Point. you can try

new Line().new Point().getPoint()

or

Line l=new Line();
Line.Point p=l.new Point();
p.getPoint();
Madhukar Ojha
Ranch Hand

Joined: Mar 21, 2007
Posts: 71
If you call method of inner class within enclosing class then

Line line = new Line();
Point p = line.new Point();
p.getPoint();

If you call method of inner class outside to enclosing class then

Line line = new Line();
Line.Point p = line.new Point();
p.getPoint();



SCJP 5 ๑۩۞۩๑♥~~ My Life is My Creation ~~♥๑۩۞۩๑
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help on accessing the method