HOTSPOT A developer designs an interface that contains the following code:
For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Answer:
Explanation:
4 Comments on “A developer designs an interface that contains the following code:”
raosays:
correct
1
2
Jsays:
YES,YES,NO
public class Program
{
public static void Main(string[] args)
{
//Class2 class2 = new Class2();
//((INewInterface)class2).Method1();
Class1 class1 = new Class1();
((INewInterface)class1).Method1();
}
}
public class Class1 : Class2{}
public class Class2 : INewInterface{
void INewInterface.Method1(){
throw new NotImplementedException();
}
}
public interface INewInterface{
void Method1();
}
2
3
Gurusays:
yes, yes, no
3
3
ivannathansays:
2nd question – If you cast class1 to interface, the exceptions is thrown.
the answer is NO, because class1 is inherited from class2, which uses interface. In other words, class1 also has interface
correct
1
2
YES,YES,NO
public class Program
{
public static void Main(string[] args)
{
//Class2 class2 = new Class2();
//((INewInterface)class2).Method1();
Class1 class1 = new Class1();
((INewInterface)class1).Method1();
}
}
public class Class1 : Class2{}
public class Class2 : INewInterface{
void INewInterface.Method1(){
throw new NotImplementedException();
}
}
public interface INewInterface{
void Method1();
}
2
3
yes, yes, no
3
3
2nd question – If you cast class1 to interface, the exceptions is thrown.
the answer is NO, because class1 is inherited from class2, which uses interface. In other words, class1 also has interface
0
1