0
0
C Sharp (C#)programming~10 mins

Interface declaration syntax in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an interface named IAnimal.

C Sharp (C#)
public [1] IAnimal
{
    void Speak();
}
Drag options to blanks, or click blank then click option'
Ainterface
Bclass
Cstruct
Denum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'interface' keyword.
Trying to use 'struct' or 'enum' which are different types.
2fill in blank
medium

Complete the code to declare an interface method named Move that returns void.

C Sharp (C#)
public interface IVehicle
{
    [1] Move();
}
Drag options to blanks, or click blank then click option'
Aint
Bbool
Cstring
Dvoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using a return type like int or string when the method should return nothing.
Omitting the return type entirely.
3fill in blank
hard

Fix the error in the interface declaration by completing the code.

C Sharp (C#)
public [1] IShape
{
    double GetArea();
}
Drag options to blanks, or click blank then click option'
Ainterface
Bstruct
Cnamespace
Dclass
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'interface'.
Using unrelated keywords like 'namespace' or 'struct'.
4fill in blank
hard

Fill both blanks to declare an interface ICalculator with a method Add that returns an int.

C Sharp (C#)
public [1] ICalculator
{
    [2] Add(int a, int b);
}
Drag options to blanks, or click blank then click option'
Ainterface
Bvoid
Cint
Dclass
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'interface'.
Using 'void' as return type when the method should return int.
5fill in blank
hard

Fill all three blanks to declare an interface IPrinter with a method Print that takes a string and returns void.

C Sharp (C#)
public [1] IPrinter
{
    [2] Print([3] message);
}
Drag options to blanks, or click blank then click option'
Ainterface
Bvoid
Cstring
Dclass
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'interface'.
Using wrong return type or parameter type.