This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can constructors use 'extends'

 
linus dale
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;


class MyCanvas extends Canvas

{

public void paint(Graphics g)

{ g.setColor(new Color(255,0,0));

g.drawOval(5,5,100,100);

g.setColor(Color.blue);

g.drawOval(15,10,120,120);



g.setColor(Color.black);

g.drawRect(10,10,30,30);


}

public MyCanvas() extends Frame
{
super("some frame");



this.add(mc);
this.setSize(300,200);
this.setVisible(true);

}

}


public class TestCanvas9

{
public static void main(String args[])

{MyCanvas mc=new MyCanvas();




}

}

doubt
why do i get
; expected error in line no. 27
i.e public MyCanvas() extends Frame
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/UseCodeTags

"extends" can only be applied to classes and interfaces. Not constructors, methods or fields.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, moving to beginner.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic