dabirbswerenoisyaround
dabirbswerenoisyaround
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
I'm not the best at c# but I hope i made things clear 😄
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
Remember that thats the simplest as it can get
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
abstract class Pet2
{
public int id;
public int health;
public int loyalty;
public int nutrition;
public int cleanliness;
public string name;

public Pet2(string name, int id, int health, int loyalty, int nutrition, int cleanliness)
{
this.id = id;
this.health = health;
this.loyalty = loyalty;
this.nutrition = nutrition;
this.cleanliness = cleanliness;
this.name = name;
}
}

class Dog2 : Pet2
{
public string breed;

public Dog2(string breed, string name, int id, int health, int loyalty, int nutrition, int cleanliness) :
base(name, id, health, loyalty, nutrition, cleanliness)
{
this.breed = breed;
}
}
abstract class Pet2
{
public int id;
public int health;
public int loyalty;
public int nutrition;
public int cleanliness;
public string name;

public Pet2(string name, int id, int health, int loyalty, int nutrition, int cleanliness)
{
this.id = id;
this.health = health;
this.loyalty = loyalty;
this.nutrition = nutrition;
this.cleanliness = cleanliness;
this.name = name;
}
}

class Dog2 : Pet2
{
public string breed;

public Dog2(string breed, string name, int id, int health, int loyalty, int nutrition, int cleanliness) :
base(name, id, health, loyalty, nutrition, cleanliness)
{
this.breed = breed;
}
}
This is how you call the base constructor
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
Thats too complex for starters i think
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
Java -> c#
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
this = this super = base
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
Super
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
I think
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
This is the simplest as it can get
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
abstract class Pet2
{
public int id;
public int health;
public int loyalty;
public int nutrition;
public int cleanliness;
public string name;
}

class Dog2 : Pet2
{
public Dog2(string name, int id, int health, int loyalty, int nutrition, int cleanliness)
{
base.id = id;
base.health = health;
base.loyalty = loyalty;
base.nutrition = nutrition;
base.cleanliness = cleanliness;
base.name = name;
}
}
abstract class Pet2
{
public int id;
public int health;
public int loyalty;
public int nutrition;
public int cleanliness;
public string name;
}

class Dog2 : Pet2
{
public Dog2(string name, int id, int health, int loyalty, int nutrition, int cleanliness)
{
base.id = id;
base.health = health;
base.loyalty = loyalty;
base.nutrition = nutrition;
base.cleanliness = cleanliness;
base.name = name;
}
}
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
There
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
abstract class Pet2 { public int id; public int health; public int loyalty; public int nutrition; public int cleanliness; public string name; } class Dog2 : Pet2 { public Dog2(string name, int id, int health, int loyalty, int nutrition, int cleanliness) { base.id = id; base.health = health; base.loyalty = loyalty; base.nutrition = nutrition; base.cleanliness = cleanliness; base.name = name; } }
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
In my mind im typing private 😄
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
OMG SORRY YES PRIVATE
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
The default is public
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
There
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
But you know access modifiers?
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
Oh
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
Have you used java before c#?
135 replies
CC#
Created by Rj on 2/17/2024 in #help
Struggling with constructor
abstract class Pet2
{
int id;
int health;
int loyalty;
int nutrition;
int cleanliness;
public string name;
}

class Dog2 : Pet2
{
public Dog2(string name)
{
base.name = name;
}
}
abstract class Pet2
{
int id;
int health;
int loyalty;
int nutrition;
int cleanliness;
public string name;
}

class Dog2 : Pet2
{
public Dog2(string name)
{
base.name = name;
}
}
This one works fine but the id to cleanliness are null
135 replies