• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Intance methods

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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)?
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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)???
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • 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.



 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • 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





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic