Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

single level inheritance in java

USING - C++

 Source Code

// Contributed by - Debojyoti Chakraborty ( GC College, Silchar - @ Department of Computer Science )
#include<iostream>
using namespace std;

class A {
	public:
		int x;
		void getData_A() {
			cout<<"Enter the value of X = ";
			cin>> x;
		}
};

//	Class-C derived from Class-A
class B : public A {
	public:
		int y;
		void getData_B() {
			cout<<"Enter the value of Y = ";
			cin>> y;
		}
};

//	Class-C derived from Class-B
class C : public B {
	public:
		int z;
		void getData_C() {
			cout<<"Enter the value of Z = ";
			cin>> z;
		}
		void showProduct() {
			cout<<"
The product of X, Y & Z is : "<< x * y * z;
		}
};

int main() {
	C obj;
	obj.getData_A();
	obj.getData_B();
	obj.getData_C();
	obj.showProduct();
	return 0;
}
Source by gcc-x-csd.github.io #
 
PREVIOUS NEXT
Tagged: #single #level #inheritance #java
ADD COMMENT
Topic
Name
4+6 =