This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Intance methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Intance methods" Watch "Intance methods" New topic
Author

Intance methods

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Hi...
Can I call instance methods if I am in another instance method of the same class(without static modifier)?


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

hope i understood your question





SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Oh I see what I'm confused about.
The static modifier needed to be added to protect the variables...
not to allow the instance method to be called.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Duran Harris wrote:The static modifier needed to be added to protect the variables...

What do you mean? The 'static' keyword does not 'protect' variables in any way.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Replying to the original question, Yes you can call an instance method (or non-static method) from another instance method...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

In this case..adding the static modifier to the synchronized method made the Thread obtain the class lock as oppossed to the 'this' lock.(I think)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Duran Harris wrote:In this case..adding the static modifier to the synchronized method made the Thread obtain the class lock as oppossed to the 'this' lock.(I think)


Duran are you talking about this post or are lost in some other post :P
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Yes.I was trying to explain to Jesper how static would protect the static variables
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

But something new now:


System.out.printf("%+(04.2f",12.6542);

Doesn't the 4.2 in the format string indicate that the number should have 4 digits before the decimal point and 2 after it(as well as signing it,enclosing negatives in brackets,padding with zeroes)???
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
to call intance methods, you must to create only one object of the class that you want. after you can call anything instance methods this class without problem.




Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Duran Harris wrote:But something new now:




Doesn't the 4.2 in the format string indicate that the number should have 4 digits before the decimal point and 2 after it(as well as signing it,enclosing negatives in brackets,padding with zeroes)???


No Duran.

4.2f, it is say 4 places minimum to be occupied including decimal point but after decimal only 2 places maximum allowed.

It will only restrict you in fractional part so .65 is allowed only

so 4.2f===> 12.65;
12345 //total 5 places occupied already
04.2f====> more than 4 places already occupied so no place remained for 0 padding so===> 12.65
(04.2f====> there is no minus sign ====>12.65
+(04.2f===> number is positive here so===> +12.65

same for






SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Intance methods
 
Similar Threads
Question about inheritance
Are instance methods on java.security.MessageDigest threadsafe
accessibility of stativ variable with in a constructor
Question about polymorphism and casting
virtual functions