Override method from parent class - Java Object Oriented Design

Java examples for Object Oriented Design:Method Override

Description

Override method from parent class

Demo Code

import java.util.*;

public class Subclass extends Superclass {
    public boolean aVariable; //hides aVariable in Superclass

    public void aMethod() { //overrides aMethod in Superclass
        aVariable = false;//from  w  w w .  j  a  v  a2  s . co  m
        super.aMethod();
        System.out.format("%b%n", aVariable);
        System.out.format("%b%n", super.aVariable);
    }
}
class Superclass {
    public boolean aVariable;

    public void aMethod() {
        aVariable = true;
    }
}

Related Tutorials