Practice #6

Download code here

What is the output of each of the following codes?

	class One
	{
	public:
		One (char c)
			: ch (c)
		{ cout<< ch<< endl;
			z = 10;		}

		int z;

	protected:
		void Doo () const
		{ cout<< "One class\n"; }

	private:
		int Foo () const
		{ return ch; }

		char ch;
	};

	class Two : public One
	{
	public:
		Two (char c, int a)
			: One (c), x (a)
		{ cout<< "Two class\n"; }

		int Moo ()
		{	//Foo ();	// error
			Doo ();
			return ++x; }

	protected:
		void Boo ()
		{ ++z; }

	private:
		int x;
	};
			
	void main ()
	{
		One one ('B');
		//one.Doo ();	// Error
		//cout<< one.Foo ()<< endl;	// Error
		cout<< one.z<< endl;

		Two two ('D', 5);
		//two.Doo ();	// Error
		//cout<< two.Foo ()<< endl;	// Error
		cout<< two.Moo ()<< endl;
		//two.Boo ();	// Error
		cout<< two.z<< endl;
	}