arttuladhar
5/14/2013 - 8:35 PM

Extending Classes - Java Tuts

Extending Classes - Java Tuts

package com.aayushtuladhar.HelloWorld;

class B {
  protected int x;

	int getX() { return x; }
	void setX(int x) { this.x = x; }
	void increase() { x = x+1; }
	void decrease() { x = x-1; }
	int returnx() { return x; }
	
}

class C extends B {
	void increase() { x = x+10; }
	void decrease() { x = x-10; }
}

public class Attr {
	public static void main(String[] args) {
		B bClass = new B();
		bClass.setX(3);
		bClass.increase();
		System.out.println(bClass.returnx());
		
		C cClass = new C();
		cClass.setX(3);
		cClass.increase();
		System.out.println(cClass.returnx());
		
		B testClass = new C();
		testClass.setX(5);
		testClass.increase();
		System.out.println(testClass.returnx());
		
	}
}