• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Color??

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code below draws a line.What is the color of the line?
g.setColor(Color.red.green.yellow.red.cyan.magenta.orange.cyan);
g.drawLine(0,0,100,100);
Options : a)red
b)Green
c)Yellow
d)Cyan
e)Black
Ans : d)Cyan......
Why is the above answer correct??Need Explainations..
Sonir
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since Color.xxx is a Color object, it will just evaluate from left to right.
(((Color.red).green).yellow).xxx and so on.
You can do the same with methods:
" Some String ".trim().toUpperCase().substring(x, y);
Since each method call is returning a String object, you can continue to call String methods on that object, evaluating from left to right.
 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it means no matter how many colors are there in the list; we need to consider only the last one???
Still not clear with the concept
Sonir
 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it means no matter how many colors are there in the list; we need to consider only the last one???
Still not clear with the concept
Sonir
 
Jim Hall
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is correct.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Color is a utility class with many public static member fields.
For example, "red" is the name of a static field in the Color class. The TYPE of red is a Color object.
So the expression
Color.red
is itself a Color object. Guess what? That Color object has a bunch of static fields in it, just like every other Color object. So,
Color.red.green is a static field of the object referenced by Color.red; it is a Color object, so you can access any of its fields:
Color.red.green.yellow.
Etc.
Hope this helps!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic