Showing posts with label Inheritance. Show all posts
Showing posts with label Inheritance. Show all posts

Monday, May 9, 2011

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

Sunday, April 10, 2011

Published 4/10/2011 by with 1 comment

call to super must be first statement in constructor

The error message is very clear actually: i) We can call super in the constructor of a subclass ii) If we call super in the constructor of a subclass, it must be the first statement in that constructor; i.e, before writing any other statement we call to super must be made. It is mentionable that, super(parameters) calls the constructor of the super class. See the code below: The super class... public...
Read More
    email this       edit

Friday, August 28, 2009

Published 8/28/2009 by with 0 comment

cyclic inheritance involving ...

public class Person extends Employee{ private String firstName; private String lastName; public Person(String firstName,String lastName) { this.firstName=firstName; this.lastName=lastName; } } Person is a class which inherits Employee and see the code below where Employee also inherit the Class Person. public class Employee extends Person{ private double salary; public Employee(String firstName,String...