RSS Forums RSS
Please support our C# advertiser: Programming Forums
Views: 1177 | Replies: 2
Reply
Join Date: Apr 2006
Posts: 5
Reputation: SharpOne is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
SharpOne SharpOne is offline Offline
Newbie Poster

Help Inheritance Problem

  #1  
Apr 18th, 2006
:-| Why won't this code work?

using System;
using System.Windows.Forms;
namespace Practice
{
	class Practice
	{
		public static void Main()
		{
			// declare and assign a string variable called human
			
                        string human;
			human = "Walking & talking life";


			// declare and assign an int variable called mind

			int mind;
			mind = 100;


			// Print the value of the variables to the console
			Console.WriteLine(mind);
			Console.WriteLine(human);
		}
	}

	class Continued
	{
		public static void notMain()

		{
			MessageBox.Show(human);
			MessageBox.Show(mind);
		}


	}

}
Last edited by alc6379 : Apr 19th, 2006 at 1:46 pm. Reason: added Code tags.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 482
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Inheritance Problem

  #2  
Apr 18th, 2006
well, to start off with the variables human and mind are neither declared nor instantiated in the Continued class, so this isn't even going to compile.
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,336
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 102
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Inheritance Problem

  #3  
Apr 19th, 2006
Did you want the class Continued to inherit from the class Practice, or did you just want Continued to create a new object of type Practice?

I'm confused.

Heck, if you even wanted to do either of those, you declared the variables inside of your Method. In order to use them in another class, or as the property of a newly instantiated Practice object, you'd want to put them in the root of the Class, as public variables. Either that, or make them private, and provide accessors for the fields using public Properties.

If you rewrite it to do that, maybe we could help more.
Alex Cavnar, aka alc6379
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:44 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC