Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Intance methods

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
Can I call instance methods if I am in another instance method of the same class(without static modifier)?
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hope i understood your question




 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Replying to the original question, Yes you can call an instance method (or non-static method) from another instance method...
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.I was trying to explain to Jesper how static would protect the static variables
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)???
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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





 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic