• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling methods  RSS feed

 
nicky priya
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi everyone. I have another doubt. In how many ways can we call a method from one class to another class.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a big vogue question. Could you please give more details about your doubt. Maybe give an example of what you're trying to achieve?
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "a way to call a method"?
 
nicky priya
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


My question is, can we call a method using a Constructor or by returning a value ( using return type).
Or by using other keywords.


Thanks in advance.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please give examples what you mean. At the moment is hard to understand where your confusion comed from.
 
nicky priya
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is a simple addition, Subtraction,Multiplication and Division program.
And calling them into another class.



}



And then calling the methods add(), sub(), mul(), div().

So using a constructor can we call the above methods.


 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nicky priya wrote:
So using a constructor can we call the above methods.


To call an instance method, you need an instance. And how you get that instance is not really ... a different "way" to call the method.

... that is like saying, going to a different pizzeria and eating a pizza, is considered a different "way" to eat a pizza...

Henry
 
nicky priya
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So there is no other instance calling a method from another class using keywords.
 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nicky priya wrote:

So there is no other instance calling a method from another class using keywords.
You can call method by referring to it via its class name where it is defined, if it is a static one.
i.e.:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!