aspose file tools*
The moose likes Beginning Java and the fly likes can  constructors  use  'extends' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can  constructors  use  Watch "can  constructors  use  New topic
Author

can constructors use 'extends'

linus dale
Ranch Hand

Joined: Jul 01, 2009
Posts: 44
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

Joined: Oct 27, 2005
Posts: 19672
    
  18

http://faq.javaranch.com/java/UseCodeTags

"extends" can only be applied to classes and interfaces. Not constructors, methods or fields.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

By the way, moving to beginner.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can constructors use 'extends'