TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aditya Patil
NA
535
134.3k
Process is terminated due to StackOverflowException.
Jul 11 2014 7:44 AM
I am working on C# Console application of Inheritance,
While running the Console application I am getting message in console "Process is terminated due to StackOverflowException"
I am not getting how to overcome this problem, I studied my code, may be did small mistake, please help me regarding it.
Program.cs
namespace Inheritance
{
class Program
{
static void Main(string[] args)
{
Employee e = new Employee();
Console.WriteLine("Employee");
Console.ReadLine();
}
}
}
Employee.cs
namespace Inheritance
{
class Employee
{
static double totalsalary,laboursalary1,managersalary1,vpsalary1;
Labour l = new Labour("ABC", 9, 100); <---------------------------Exception thrown here as stackoverflowexception
Manager m = new Manager("PQR", 10000, 5000, 1000);
VicePresident vp = new VicePresident("XYZ", 20000, 10000, 5000);
SalesManager sm = new SalesManager("KLM", 8000, 2000, 500, 50);
public Employee()
{
laboursalary1 = l.getTotalSalary();
managersalary1 = m.getTotalSalary();
vpsalary1 = vp.getTotalSalary();
}
public static double calculateTotalSalary(Labour l, Manager m, VicePresident vp, SalesManager sm)
{
totalsalary = laboursalary1 + managersalary1 + vpsalary1;
Console.WriteLine(totalsalary);
return totalsalary;
}
Labour.cs
namespace Inheritance
{
class Labour:Employee
{
private string p1;
private double p2;
private double p3;
public Labour(string p1, double p2, double p3)
{
Console.WriteLine("Labour");
// TODO: Complete member initialization
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
}
public double getTotalSalary()
{
double laboursalary= p2*p3;
Console.WriteLine(laboursalary);
return laboursalary;
}
}
}
}
}
The exception is thrown at above specified code. How I can solve this problem, this Exception?
Manager.cs
namespace Inheritance
{
class Manager:Employee
{
private string p1;
private double p2;
private double p3;
private double p4;
public Manager(string p1, double p2, double p3, double p4)
{
Console.WriteLine("Manager");
// TODO: Complete member initialization
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
getTotalSalary();
}
public double getTotalSalary()
{
double managersalary = p2 + 30% p3 + p4;
Console.WriteLine(managersalary);
return managersalary;
}
}
}
SalesManager.cs
namespace Inheritance
{
class SalesManager:Manager
{
private string p1;
private double p2;
private double p3;
private double p4;
private double p5;
public SalesManager(string p1, double p2, double p3, double p4, double p5):base("PQR", 10000, 5000, 1000)
{
Console.WriteLine("salesmanager");
// TODO: Complete member initialization
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
this.p5 = p5;
getTotalSalary();
}
public new double getTotalSalary()
{
double smsalary= p2 + 50% p3 + p4;
Console.WriteLine(smsalary);
return smsalary;
}
}
}
VicePresident.cs
namespace Inheritance
{
class VicePresident:Employee
{
private string p1;
private double p2;
private double p3;
private double p4;
public VicePresident(string p1, double p2, double p3, double p4)
{
Console.WriteLine("VP");
// TODO: Complete member initialization
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.p4 = p4;
getTotalSalary();
}
public double getTotalSalary()
{
double vpsalary= p2 + 50 % p3 + p4;
Console.WriteLine(vpsalary);
return vpsalary;
}
}
}
Reply
Answers (
2
)
Image not pasted in blog
Remote Control With C#