Practice: Constructors
A simple class called Dog
is given. Create a constructor which takes in the arguments name
, breed
, age
, and initializes the fields from the values of arguments.
index.cs
123456789101112131415161718192021222324using System; class Dog { public string name; public string breed; public int age; // Write constructor code below this line // Write constructor code above this line public void bark() { Console.WriteLine("Woof!"); } } public class ConsoleApp { public static void Main(string[] args) { Dog dog = new Dog("Dobby", "Dobermann", 4); dog.bark(); } }
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 10
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 2.04
Practice: Constructors
Svep för att visa menyn
A simple class called Dog
is given. Create a constructor which takes in the arguments name
, breed
, age
, and initializes the fields from the values of arguments.
index.cs
123456789101112131415161718192021222324using System; class Dog { public string name; public string breed; public int age; // Write constructor code below this line // Write constructor code above this line public void bark() { Console.WriteLine("Woof!"); } } public class ConsoleApp { public static void Main(string[] args) { Dog dog = new Dog("Dobby", "Dobermann", 4); dog.bark(); } }
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 10