Showing posts with label overriding. Show all posts
Showing posts with label overriding. Show all posts

Friday, May 20, 2011

Published 5/20/2011 by with 2 comments

attempting to use incompatible return type

We may encounter this error message when we override a superclass method in the subclass with a wrong return type in the subclass method. To understand this, let's see the following two classes. public class SuperClass { public double sum(double a,double b) { return (a+b); } } public class Subclass extends SuperClass { public long sum(double a,double b) { return Math.round(a+b); } } In...
Read More
    email this       edit

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
Published 5/19/2011 by with 2 comments

attempting to assign weaker access privileges

Java error "attempting to assign weaker access privileges" can happen when we override a superclass method in the subclass if the access modifier is not correctly chosen. See the sample code below: public class SuperClass { public void display() { System.out.println("this is super class"); } } public class Subclass extends SuperClass { private void display() { System.out.println("this...
Read More
    email this       edit