I was watching a video on making a game in Java and saw the following code for creating a BufferStrategy object:
public void render() {
BufferStrategy bs = getBufferStrategy();
if bs==null {
createBufferStrategy(3);
return
}
}
I've seen this exact block of code in other examples and videos, so it seems pretty standard. My question is, since neither getBufferStrategy() or createBufferStrategy() are static methods, shouldn't they be called with an object? And since this render method belongs to a class that extends the Canvas class, shouldn't the code look like this?:
public void render() {
BufferStrategy bs = this.getBufferStrategy();
if bs==null {
this.createBufferStrategy(3);
return
}
}
The docs.oracle page for the Canvas class lists these methods as non-static. So why is it ok for us to call them without an object? Any help is greatly appreciated.
Copyright Notice:Content Author:「robzoid」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40901220/calling-getbufferstrategy-and-createbufferstrategy-without-an-object