- 1
Java methods, statements, functions and class
ok im trying to figure out what order things go and if i have it right in my head. im assuming that "if()" or anthing that ends with "()" is a method which invokes things? String x = "hello world"; System.out.println(x); << is this a method within a statement? if so im assuming that a method is somthing that functions within a statement in a class? if thats right the function output would be "hello world"? or is the function the method? lol so confused 😕..
2 Respostas
+ 2
A class is like a blueprint for what will be instantiated into an object. It can contain properties (member variables), methods, and inner classes.
Methods live inside a Class. Functions are basically the same as methods, but they stand alone outside of a class. Java doesn't have functions technically, but the terms method and function are often used interchangeably.
class A {
public void myMethod() {
}
}
A Statement is basically a line of code.
int x = 42; // statement declaring a variable
System.out.println(x); // statement calling a method
0
methods in oop are functions in a class