Computer Science 225
Advanced Programming

Spring 2017, Siena College

OverrideAccessControl BlueJ Project

Click here to download a BlueJ project for OverrideAccessControl.


OverrideAccessControl Source Code

The Java source code for OverrideAccessControl is below. Click on a file name to download it.


OverrideAccessControl.java

/*
 * Example OverrideAccessControl
 *
 * Jim Teresco, Siena College, Computer Science 225, Spring 2017
 *
 * $Id: templateapp.java 2975 2016-08-30 02:35:29Z terescoj $
 */

class A {
    
    public int m1() {
        
        return 1;
    }
    
    protected int m2() {
        
        return 2;
    }
    
    int m3() {
        
        return 3;
    }
    
    private int m4() {
        
        return 4;
    }
}

class B extends A {
    
    // we can give each overridden method the same access control
    // or something less restrictive
    //
    // change below to see which ones work
    @Override
    public int m1() {
        
        return 11;
    }
    
    @Override 
    public int m2() {
        
        return 12;
    }
    
    @Override
    public int m3() {
        
        return 13;
    }
    
    /* An actual "override" not allowed at all since m4 is private */
    //@Override
    public int m4() {
        
        return 14;
    }
    
    
}


public class OverrideAccessControl {

    public static void main(String[] args) {
	
    }
}