Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Inheritance

Posted on 2008-09-30
4
Medium Priority
?
197 Views
Last Modified: 2012-05-05
I have written code in one file(FoodItem.cs).Solution name is ConsoleApplication2:
using System;

namespace ConsoleApplication2
{
      /// <summary>
      /// Summary description for FoodItem.
      /// </summary>
      public class FoodItem
      {
            
            extern int  Calories_Per_Gram=9;
            private  int fatgrams;
            protected int servings;            
      
            public FoodItem(int Fatgrams1,int servings1)
            {
                  fatgrams=Fatgrams1;
                  servings=servings1;
            }
            
            private int Calories()
            {
                  return fatgrams *Calories_Per_Gram ;
            }

            public int CaloriesPerSavings()
            {      
                  return(Calories ()/servings );
            }
      }

}

I build the above file.
Now in Another file(Pizza.cs) in ConsoleApplication2,I code:

using System;

namespace ConsoleApplication2
{
      /// <summary>
      /// Summary description for Pizza.
      /// </summary>
 public class Pizza extends  FoodItem
      {
            public Pizza (int FatGrams)
                  {
                        super(Fatgrams,8);
                  }
            }
      
}


It is showing errors:
1) at extern
2) public pizza(at the constructor)
3) at super
0
Comment
Question by:sarang8180
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:xRalf
xRalf earned 600 total points
ID: 22603820
Hello sarang8180,

extends and super are not C# keywords. Maybe you were using java. Try to look at the C# syntax.

Regards,

xRalf
0
 
LVL 10

Accepted Solution

by:
oxyoo earned 1400 total points
ID: 22603833
Hi,

Here's a working example (namespace part not included)...
    /// <summary>
    /// Summary description for FoodItem.
    /// </summary>
    public class FoodItem
    {
        private extern int Calories_Per_Gram = 9;
        private readonly int fatgrams;
        protected int servings;
 
        public FoodItem()
        {
        }
 
        public FoodItem(int Fatgrams1, int servings1)
        {
            fatgrams = Fatgrams1;
            servings = servings1;
        }
 
        private int Calories()
        {
            return fatgrams*Calories_Per_Gram;
        }
 
        public int CaloriesPerSavings()
        {
            return (Calories()/servings);
        }
    }
 
 
 
 
 
 
    /// <summary>
    /// Summary description for Pizza.
    /// </summary>
    public class Pizza : FoodItem
    {
        public Pizza(int fatGrams) : base(fatGrams, 8)
        {
        }
    }

Open in new window

0
 

Author Comment

by:sarang8180
ID: 22603998
now it is showing error in FoddItem.cs

the modifier 'extern' is not valid for this item
0
 
LVL 10

Expert Comment

by:oxyoo
ID: 22604008
Hi,

Change
        private extern int Calories_Per_Gram = 9;

To
        private readonly int Calories_Per_Gram = 9;

You are not allowed to use extern there.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question