Difficulty in inheriting Abstract Class
I am trying to work thru Visual Studio Hosted examples using J# - The examples
only discuss C# and VB so I am trying to come up with the equivalent J#.
I am stuck on code similar to the following: ( I have simplified it a bit to what is in
the example - the example using C# )
Add Class: Company:
using System;
namespace Northwind
{
public abstract class Company
{
public int ID;
public string Name ;
public Company( int ID, string Name )
{
this.ID = ID;
this.Name = Name;
}
}
}
Create a new Class: Customer that inherits the abstract class Company
using System;
namespace Northwind
{
public class Customer : Company
{
public Customer() : base(){}
public Customer( int ID, string Name ) : base( ID, Name )
{
}}
}
I cannot seem to come up with how to write the class for Customer in J#
I would be very grateful for any help with this, I have been stuck on this for
hours and hours - thanks
Your Customer class won't compile because your parameterless constructor is calling a base class constructor with no arguments - base() - which doesn't exist. If you don't declare any constructor, you get a default parameterless constructor for free. (If you don't want any constructor at all, you can declare a private parameterless constructor or - in .NET 2.0 - declare the class static.)
public class CannotInstaniateMe {
private CannotInstaniateMe() { }
}
OR
public static class CannotInstaniateMe { // C# 2.0 only
}
Also, there is no need to specify base() to call the base class constructor as this is done by default. You only need to specify base(whatever) if you want to chain to a parameterized constructor.
If you're trying to implement this in J#, you need to use the implements keyword.
public class Customer extends Company {
public Customer(int id, string name) {
super(id, name);
}
}
OK - thanks - the C# code is taken from the Visual Studio Soup to Nuts
Lab 4,
I got similar code to work in J# by taking out the modifier "abstract" in the Company class definition, then by using "Customer extends Company" as you
indicated and finally by taking out the parameterless constructor - it must have some strange meaning in C#, also used "super" to "instantiate" the class. The lab manual refers to the "base constructor" in C# as being used to initialize the entire class - at any rate that fixes that.
I am also looking for info on printing reports in J# - thanks