Java Program to demonstrate Single Inheritance

Write a Java program to demonstrate single inheritance.



Source Code
class AA {
	
	int i;
	
	void showI() {
		
		System.out.println("i = "+i);
	}
}

class BB extends AA {

	int j;
	
	void showJ() {
		
		System.out.println("j = "+j);
	}
}

public class SingleInhDemo {

	public static void main(String[] args) {
		
		AA a = new AA();
		BB b = new BB();
		
		a.i = 56;
		b.j = 23;
		
		a.showI();
		b.showJ();
	}
}
Output
i = 56
j = 23





"Coding Hub - Learn to code" app now available on Google Play Store