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
venus najad
1.3k
414
29.1k
polymorphism on abstract class
Mar 27 2019 7:46 AM
hello... i have an issue and need help... i will calculate two circuits with two resistors, parallel or serie... for this i have created an abstract class KretsDel, which has two protected fields(resistors), and abstract property, Total and a constructor.
further i have created two classes Parallel and Serie, which contains the propertyTotal which returns the result of resistors connections.
further i have created a class Krets with a field List<KretsDel> and two methoder for calculation of serie or parallel coupling for each element in List<KretsDel>... but i get errors...
the following is my codes:
class
Program
{
static
void
Main(
string
[] args)
{
Krets k =
new
Krets();
}
}
abstract
class
KretsDel
{
protected
float
R1, R2;
public
abstract
float
Total
{
get
;
set
;
}
public
KretsDel(
int
r1,
int
r2)
{
this
.R1 = r1;
this
.R2 = r2;
}
}
class
Parallel : KretsDel
{
override
public
float
Total
{
set
{
this
.R1 = value;
this
.R2 = value;
}
get
{
return
parallel(
this
.R1,
this
.R2); }
}
public
float
parallel(
float
r1,
float
r2)
{
float
R = r1 *r2 / (r1 + r2);
return
R;
}
}
class
Serie : KretsDel
{
override
public
float
Total
{
set
{
this
.R1 = value;
this
.R2 = value;
}
get
{
return
serie(
this
.R1,
this
.R2); }
}
public
float
serie(
float
r1,
float
r2)
{
float
R =r1 + r2;
return
R;
}
}
public
class
Krets
{
static
Parallel parallel =
new
Parallel();
static
Serie serie =
new
Serie();
List<KretsDel> lkd =
new
List<KretsDel>() { parallel, serie };
foreach
(var k
in
lkd)
k.Total;
public
float
ser(
float
r1,
float
r2)
{
float
R = r1 + r2;
return
R;
}
public
float
para(
float
r1,
float
r2)
{
float
R = r1 * r2 / (r1 + r2);
return
R;
}
}
appreciate any help... kind regards
Reply
Answers (
5
)
jAVASCRIPT opening link in new tab
ebay GetOrders call