Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: What is the difference between subroutine and methods?

What is the difference?

public write(){
// dostuff
}

Is the code above a subroutine, a method, or a program block?

I don't understand these terms because the meaning of them are all so similar?

So, if I was being very strict and pedantic, then which one would it be? I prefer calling them subroutines, is this STRICTLY correct?

Programming language: JAVA

EDIT: Thanks, I understand now but what would be the safest way to call it? Block? I use multiple programming languages, would the term "block" suffice?

Can I call a function a block?

So can I refer everything as a block? It will be easier for me, right?

I won't call a block a function or subroutine, but I will call a function, methods and whatever as a block. Would that be fine, calling them as a block?

So, does this mean this is somewhat ACCURATE? A local variable is not accessed outside of the program block (yes, there are a few circumstances that this is not true).

like image 625
user2421111 Avatar asked Oct 20 '25 01:10

user2421111


1 Answers

  1. A subroutine is something you can call that returns to you.
  2. A function is a subroutine that returns a a value.
  3. A method is a subroutine or function that you can call on an object in an OO language.
like image 85
user207421 Avatar answered Oct 21 '25 16:10

user207421



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!