0

I've been searching/reading docs from Oracle for about 2 hours, and I'm pretty stumped. I had thought I understood what an abstract class was, and how it was used (at a basic level, at least). I'm still fairly new to all this, so bear with me please.

As I understand it, an abstract class cannot be instantiated, and instead requires a subclass to implement any part of it. The classes I was looking at, trying to dissect and understand, were BufferStrategy and Canvas, as well as how they work together. I'm not using these classes in a project, more or less just want to understand how they work.

So, let's say I have my Canvas and am creating a BufferStrategy for it:

BufferStrategy bs;
Canvas c;
c = new Canvas();
c.createBufferStrategy(2);
bs = c.getBufferStrategy();

The docs say ".getBufferStrategy()" returns the BufferStrategy currently being used in Canvas. It's obviously not returning an instance of BufferStrategy, so what exactly is it returning, and how is it being stored in "bs"? Also, what would I even refer to "bs" as, when "canvas" would be: "an instance of Canvas"?

I noticed the only subclasses of BufferStrategy, "Component.BltBufferStrategy & Component.FlipBufferStrategy", which I as far as I can tell are nested in Component, and thus shared with Canvas. But I fail to see anywhere that it comes into play.

I hope all this made sense. I apologize if this is a simple basic level question I should know by now, but it's the first thing in the last year that has actually stumped me; probably because I didn't understand certain concepts as well as I had thought. Thank you for reading.

  • Would it be fair to say that your question is really about "how do references (or maybe variables) work in Java?"? – Oliver Charlesworth Feb 07 '18 at 20:20
  • If BltBufferStrategy extends BufferStrategy so you can assign it to a BufferStrategy reference, in this case only methods from the BufferStrategy will be available to call. If you want to call a method that is specific for BltBufferStrategy then you need to cast the object to a reference of its type. – Marcos Vasconcelos Feb 07 '18 at 20:30
  • Oh man. @Marcos Vasconcelos Thanks for putting me back on the right track. Immediately after reading your replies, it clicked. I think I should've just gotten up from my desk for a bit, 'cause I had gotten in a rut, and started thinking about it in the wrong way. Thank you both! – HotSoupp Feb 07 '18 at 23:04

0 Answers0