Showing posts with label Interface. Show all posts
Showing posts with label Interface. Show all posts

Thursday, May 19, 2011

Published 5/19/2011 by with 5 comments

is not abstract and does not override abstract method

See the code below: import javax.swing.JFrame; import javax.swing.JButton; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MyFrame extends JFrame implements ActionListener{ private JButton exitButton = new JButton("Exit"); public MyFrame() { Container container = getContentPane(); container.setLayout(new...
Read More
    email this       edit

Monday, May 9, 2011

Published 5/09/2011 by with 1 comment

modifier static not allowed here

Java error "modifier static not allowed here" can occur for any of the following reasons: 1. Constructor is declared as static(!) A constructor cannot be static. In the wrong code below: public class Person { private String firstName; private String lastName; public static Person() { //... } } Here the constructor Person is declared as static. As the constructor must be non-static, the...
Read More
    email this       edit
Published 5/09/2011 by with 1 comment

interface methods cannot have body

Java error "interface methods cannot have body" occurs when body of the method within an interface is defined. See the code below: public interface MyInterface { public void myMetod() { } } Here the method myMethod has body starting at the symbol { and ending at }. An interface can have abstract methods (method without any body). The class that implements the interface defines the body of the...
Read More
    email this       edit
Published 5/09/2011 by with 0 comment

interface expected here

The code below leads to an error "interface expected here" public interface MyInterface extends Thread { } Here an interface is created (MyInterface) and it inherits(extends) the Thread class which is not possible at all. Why? Because an interface can inherit only another interface, not any class. As Thread is a class, it cannot be inherited by any interface. The code below is correct as the interface...
Read More
    email this       edit
Published 5/09/2011 by with 0 comment

no interface expected here

Any Java code as below will lead an error "no interface expected here" import java.io.Serializable; public class Person extends Serializable { private String firstName; private String lastName; //... } See that, here Person is a class (public class Person) and it inherits an interface (extends Serializable). Note that a class can inherit another class only, not any interface. A...
Read More
    email this       edit

Wednesday, August 19, 2009

Published 8/19/2009 by with 5 comments

class, interface, or enum expected

You see this error message because of any one of the followings: 1. You misspelled the keyword class (fully lower case) or you did not write it at all for writing your class. public Class Test //actual keyword is class { public void myMethod() { System.out.println("class, interface, or enum expected?"); } } In the above example Class (C is in upper case) is written instead of class (fully lower...
Read More
    email this       edit