Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can Inheritance break Encapsulation.?

807589Jul 4 2008 — edited Jul 4 2008
How can inheritance break encapsulation?
class Base
{
	private int i;

	public Base(int i){
		this.i = i;
	}

	public void getInt(){
		return i;
	}

	public int setInt(int x){
                // Do some valid checks here before returning a value.
                this.i = x;
	return i;
	}

}

class Derived extends Base{

	// If I override any of the above methods
	// how can inheritance break the
                // the encapsulated code of class Base

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 1 2008
Added on Jul 4 2008
1 comment
1,017 views