MCTS Application Development & Programming 3 — Questions and Answers
Question 1: Which design pattern ensures a class has only one instance and provides a global access point to it?
- Factory
- Observer
- Singleton (Correct answer)
- Decorator
Correct answer: Singleton
The Singleton pattern restricts instantiation of a class to one object and provides a static method to access that instance.
Question 2: In C#, what is boxing?
- Converting a reference type to a value type
- Converting a value type to an object reference type (Correct answer)
- Copying a struct to another struct
- Allocating memory on the stack for a class
Correct answer: Converting a value type to an object reference type
Boxing is the implicit conversion of a value type (like int) to type object, which allocates heap memory for the value.
Question 3: Which WCF binding is most appropriate for communication between two .NET applications on the same machine?
- BasicHttpBinding
- WSHttpBinding
- NetTcpBinding
- NetNamedPipeBinding (Correct answer)
Correct answer: NetNamedPipeBinding
NetNamedPipeBinding uses named pipes for inter-process communication on the same machine, offering the best performance in that scenario.
Question 4: In LINQ, what does the 'deferred execution' concept mean?
- The query is compiled at design time
- The query is executed only when results are iterated (Correct answer)
- The query is cached after first execution
- The query runs on a background thread
Correct answer: The query is executed only when results are iterated
LINQ queries with deferred execution are not evaluated until the query variable is iterated, enabling dynamic composition.
Question 5: Which ASP.NET mechanism allows you to store user-specific data across multiple requests without a database?
- Application State
- Cache
- Session State (Correct answer)
- View State
Correct answer: Session State
Session State stores per-user data server-side and associates it with the user's browser session via a session ID cookie.
Question 6: What is the role of the 'abstract' keyword when applied to a method in C#?
- The method has a default implementation that can be overridden
- The method has no implementation and must be overridden in derived classes (Correct answer)
- The method cannot be called from outside the class
- The method is optimized by the JIT compiler
Correct answer: The method has no implementation and must be overridden in derived classes
An abstract method declares the signature only, with no body, and forces all non-abstract derived classes to provide an implementation.
Question 7: When using SQL Server with ADO.NET, what is the main advantage of using stored procedures over inline SQL?
- Stored procedures always return faster results
- They prevent SQL injection and benefit from execution plan caching (Correct answer)
- They automatically handle transactions
- They eliminate the need for connection pooling
Correct answer: They prevent SQL injection and benefit from execution plan caching
Stored procedures use parameterized inputs (preventing SQL injection) and their execution plans are cached by SQL Server for reuse.
Which design pattern ensures a class has only one instance and provides a global access point to it?