 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IT Answers &#187; Class</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/tag/class/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 14:27:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>how to stop execution of a code until a Jwindow is closed?</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/how-to-stop-execution-of-a-code-until-a-jwindow-is-closed/</link>
		<comments>http://itknowledgeexchange.techtarget.com/itanswers/how-to-stop-execution-of-a-code-until-a-jwindow-is-closed/#comments</comments>
		<pubDate>Thu, 17 Jan 2013 16:41:42 +0000</pubDate>
		<dc:creator>hussain22juzer</dc:creator>
				<category><![CDATA[Class]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JWindow]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[Swing]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/how-to-stop-execution-of-a-code-until-a-jwindow-is-closed/</guid>
		<description><![CDATA[New Answer by jailall101]]></description>
				<content:encoded><![CDATA[New Answer by jailall101]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/itanswers/how-to-stop-execution-of-a-code-until-a-jwindow-is-closed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Interfaces and Properties</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/interfaces-and-properties/</link>
		<comments>http://itknowledgeexchange.techtarget.com/itanswers/interfaces-and-properties/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:55:16 +0000</pubDate>
		<dc:creator>Gent01</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[Public Properties]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Since you can&#8217;t put properties into a c# interface, how do you expose each classes public properties when consuming the class as an interace instance? interface iAnimal {     bool Load(int Id);     bool Save(); } class Fish : iAnimal {     private string description;     public string Description     {          get { return [...]]]></description>
				<content:encoded><![CDATA[<p>Since you can&#8217;t put properties into a c# interface, how do you expose each classes public properties when consuming the class as an interace instance?</p>
<pre>


interface iAnimal

{

    bool Load(int Id);

    bool Save();

}



class Fish : iAnimal

{
    private string description;


    public string Description

    {
         get { return this.description; }
         set { this.description = value; }

    }

    public bool Load(int Id)
    {
        ...
    }



    public bool Save()

    {

        ...

    }

}







class Dog : iAnimal


{
    private string description;

    private string hypernessLevel;




    public string Description


    {

         get { return this.description; }

         set { this.description = value; }


    }



    public string hypernessLevel



    {


         get { return this.hypernessLevel; }


         set { this.hypernessLevel = value; }



    }



    public bool Load(int Id)

    {

        ...

    }






    public bool Save()


    {


        ...


    }


}


iAnimal animal;

Switch (TypeOfAnimal)
{
    case "Fish":
        animal = new Fish();
        break;
    case "Dog":

        animal = new Dog();

        break;
}

txtDescription.Text = animal.Description //How would you expose description and dog's hpernessLeve?
</pre>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/itanswers/interfaces-and-properties/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How you change a pointer from base class to derived class?</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/how-you-change-a-pointer-from-base-class-to-derived-class/</link>
		<comments>http://itknowledgeexchange.techtarget.com/itanswers/how-you-change-a-pointer-from-base-class-to-derived-class/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 11:07:29 +0000</pubDate>
		<dc:creator>CppStudent</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ classes]]></category>
		<category><![CDATA[cast]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Derived class]]></category>
		<category><![CDATA[Pointer]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Hello, I have the following classes class Rock { public: Rock() { goldAmount = rand() % 100 + 1; price = 10; }; int revealContent() { return goldAmount; }; virtual void checkPrice() { cout &#60;&#60; price &#60;&#60; endl; }; protected: int price; private: int goldAmount; }; class ValuableRock : public Rock { public: ValuableRock() { [...]]]></description>
				<content:encoded><![CDATA[<p>Hello, I have the following classes</p>
<pre>
class Rock {
public:
  Rock() { goldAmount = rand() % 100 + 1; price = 10; };
  int revealContent() { return goldAmount; };
  virtual void checkPrice() { cout &lt;&lt; price &lt;&lt; endl; };
protected:
  int price;
private:
  int goldAmount;
};

class ValuableRock : public Rock {
public:
  ValuableRock() { price = 100; }; // Try to set the new price in constructor
};

class PreciousRock : public Rock {
public:
  PreciousRock() { }; // Try changeing new price in overloaded function instead
  virtual void checkPrice() { cout &lt;&lt; price * 100 &lt;&lt; endl; };
};

void main() {
  srand((unsigned int)time(NULL));
  Rock **bagOfRocks = new Rock*[3];
  for (int i = 0; i &lt; 3; i++) {
    bagOfRocks[i] = new Rock;	// 3 random rocks in a bag
  }
  // just crack open some of the rocks
  // first method
  if (bagOfRocks[1]-&gt;revealContent() &lt;= 70) {  // not many gold inside
  //... something I dont know how to write but I tried this
    bagOfRocks[1] = (ValuableRock*)bagOfRocks[1];
  } else if (bagOfRocks[1]-&gt;revealContent() &gt; 70) {  // many gold inside
  //... again, I dont know how to write
    bagOfRocks[1] = (PreciousRock*)bagOfRocks[1];
  }
  // second method
  if (bagOfRocks[2]-&gt;revealContent() &lt;= 70) {
    //... something I dont know how to write but I also tried this
    delete bagOfRocks[2];
    bagOfRocks[2] = new ValuableRock;	// but the content of rock is rand()
                                        // may not necessary &lt;= 70 this time
  } else if (bagOfRocks[2]-&gt;revealContent() &gt; 70) {
    //... again, I dont know how to write
    delete bagOfRocks[2];
    bagOfRocks[2] = new PreciousRock;	// but the content of rock is rand()
                                        // may not necessary &gt; 70 this time
  }
  for (int i = 0; i &lt; 3; i++) {
    bagOfRocks[i]-&gt;checkPrice();// I expect it to output 10 100or1000 100or1000
  }
  for (int i = 0; i &lt; 3; i++) {
    delete bagOfRocks[i];
    bagOfRocks[i] = NULL;
  }
  delete [] bagOfRocks;
  bagOfRocks = NULL;
} 
</pre>
<p>Here I have a base class Rock, which can have random number of gold amount.<br />
If after a rock object is created, I check how many gold is inside<br />
If there is less than 71 gold, I have to change it to a ValuableRock<br />
If there is more than 70 gold, I have to change it to a PreciousRock<br />
Rocks uncracked is still ordinary Rock<br />
but once cracked, it has to be either ValuableRock or PreciousRock<br />
and by calling checkPrice(), it should print out the corresponding price</p>
<p>I tried to type cast the pointer type (method 1) but it does not call the corresponding function<br />
then I tried to delete the object (method 2) and create an appropriate object using the same base class pointer, this way the correct checkprice is called, but since it creates a new object, the gold amount is another random one</p>
<p>Can anyone provide a good solution for me so that<br />
1. I can access all kind of rock classes using an array of pointers<br />
2. gold must rand() in the base class, not in the main() then assign appropriate class of xxxRocks construction because not all Rocks are cracked at time of creation<br />
3. class hierarchy Rock, ValuableRock, PreciousRock must be maintained. (I know there is solution that can be done within a single class)</p>
<p>Thank you everyone!</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/itanswers/how-you-change-a-pointer-from-base-class-to-derived-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/18 queries in 0.033 seconds using memcached
Object Caching 468/498 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-22 21:59:58 -->