• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with graphics Object  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just read that in order to get the functionality that Graphics2d provide, but not the Graphics class,
we cascade the graphics2d as follows...

now,
afaik, we cascade the .bigger values into the smaller ones,
for example..

if we replace int with float ( or vice-versa ) then, that wouldn't work!
then how is it possible here with Graphics and Graphics2d ??
 
Java Cowboy
Sheriff
Posts: 16083
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's called casting, not cascading.

It's possible with Graphics2D and Graphics because Graphics2D is a subclass of class Graphics, and the object that g refers to is actually a Graphics2D object (even though the type of the variable is Graphics).

Casting is explained in The Java Tutorials on the page about inheritance.
 
Marshal
Posts: 58436
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
…and the Java Language Specification about narrowing primitive conversions. But it may be difficult to read.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!