13
2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 1/13 C# Questions & Answers – Properties and its Applications Advertisements This section of our 1000+ C# multiple choice questions focuses on properties and it’s application in C# Programming Language. 1. Correct way to implement a read only property add in a math class? a) 1. class math 2. { 3. int ad; 4. public int add 5. { 6. get 7. { 8. return ad; 9. } 10. } 11. 12. } b) 1. class math 2. { 3. public int add 4. { 5. get 6. { Advertise Here Best Training Courses SAN I - Technology Training SAN II - Administration Training Linux Fundamentals/Administration Advanced C Programming Linux-C Debugging Techniques Linux System Programming Linux IPCs Programming Linux Network Programming Linux Multithreaded Programming Linux Kernel Programming Linux Kernel Debugging Device Driver Trainings Linux Device Drivers Basics Linux Block Device Drivers Linux Network Device Drivers Linux PCI Device Drivers Linux USB Device Drivers Linux Video Device Drivers Linux Audio Device Drivers Linux I2C Device Drivers Advertisements Hover to Expand THERE WILL BE HATERS Home About Courses | Fees | Dates College-Projects Testimonials Internship Developers Jobs Contact C-Tutorials C-MCQs C++MCQs Java-MCQs C#MCQs Linux-MCQs SAN-MCQs Computer-Science-MCQs C-Programs Best-Books

C# Questions & Answers - Properties and Its Applications _ Sanfoundry1

Embed Size (px)

DESCRIPTION

C# Questions & Answers - Properties and its Applications

Citation preview

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 1/13

C# Questions & Answers –Properties and its Applications

Advertisements

This section of our 1000+ C# multiple choice questions focuses onproperties and it’s application in C# Programming Language.

1. Correct way to implement a read only property add in a math class?a)

1. class math2. {3. int ad;4. public int add5. {6. get7. {8. return ad;9. }

10. }11. 12. }

b)

1. class math2. {3. public int add

4. {5. get6. {

Advertise Here

Best TrainingCourses

SAN I - Technology TrainingSAN II - Administration TrainingLinux Fundamentals/AdministrationAdvanced C ProgrammingLinux-C Debugging TechniquesLinux System ProgrammingLinux IPCs ProgrammingLinux Network ProgrammingLinux Multithreaded ProgrammingLinux Kernel ProgrammingLinux Kernel Debugging

Device DriverTrainings

Linux Device Drivers BasicsLinux Block Device DriversLinux Network Device DriversLinux PCI Device DriversLinux USB Device DriversLinux Video Device DriversLinux Audio Device DriversLinux I2C Device Drivers

Advertisements

Hover to Expand

THERE WILL BEHATERS

Home About Courses | Fees | Dates College-Projects Testimonials Internship Developers

Jobs Contact

C-Tutorials C-MCQs C++MCQs Java-MCQs C#MCQs Linux-MCQs SAN-MCQs

Computer-Science-MCQs C-Programs Best-Books

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 2/13

6. {7. return ad; 8. }9. }

10. }

c)

1. class math2. {3. int ad;4. public int add5. {6. get7. {8. return ad;9. }

10. set11. {12. ad = value; 13. }14. }15. }

d) None of the mentionedView Answer

2. Correct way to implement a write only property add in a math class?a)

1. class math2. {3. public int add4. {5. set6. {7. add = value;8. }9. }

10. }

b)

1. class math

Technical CareerDeveloper TracksSAN DeveloperLinux System DeveloperLinux Kernel/Driver DeveloperLinux Network DeveloperMentoringProductivityCoding-StyleGDB AssignmentFeedback

Advertisements

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 3/13

1. class math2. {3. int ad;4. public int add5. {6. set7. {8. ad = value;9. }

10. }11. }

c)

1. class math2. {3. int ad;4. public int add5. {6. get7. {8. return ad;9. }

10. set11. {12. ad = value;13. }14. }15. }

d) None of the mentionedView Answer

3. Select the correct statement about properties in C#.NET?a) A property can simultaneously be read or write onlyb) A property can be either read only or write onlyc) A write only property will have only get accessord) A read only property will have only get accessor

View Answer

4. What will be the output of following snippet of code?

1. class number2. {3. private int num1;

1000 C# MCQs |Quiz

Integer Data TypesFloating and Decimal Data TypesChar Types and String LiteralsInitialization of VariablesScope and Lifetime of VariablesType Conversion in ExpressionsArithmetic OperatorsRelational and Logical OperatorsBit-wise and Conditional OperatorsIF StatementsSwitch StatementsFor Loop StatementsWhile Loop StatementsDo While Loop StatementsContinue, Goto statementsFundamentals of ClassReference Variables and AssignmentMethods in ClassConstructors in ClassDestructors in ClassArray and InitializationBasic Operation on StringsString Class with DescriptionComparison of StringsSearching and Modifying StringsOperation on CharactersPublic & Private Access ModifierUse of Ref and Out ParametersUse of Variable ArguementsPolymorphismStructuresEnumerations

Fundamentals of InheritanceInheritance ImplementationMethod OverloadingMethod OverridingConstructor OverloadingAbstract Class & MethodsIntroduction of Overloaded OperatorsRecursion

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 4/13

4. private int num2;5. public int anumber6. {7. get8. {9. return num1;

10. }11. set12. {13. num1 = value;14. }15. }16. public int anumber117. {18. get19. {20. return num2;21. }22. set23. {24. num2 = value;25. }26. }27. }28. class Program29. {30. public static void Main(string[] args)31. {32. number p = new number();33. p.anumber = 20;34. number k = new number();35. k.anumber1 = 40; 36. int m = p.anumber;37. int t = k.anumber1;38. int r = p.anumber + k.anumber1;39. Console.WriteLine("number = " +m);40. Console.WriteLine("number = " +t);41. Console.WriteLine("sum = " +r);

42. Console.ReadLine();43. }44. }

a) 0b) Compile time errorc) 60d) None of the above mentioned

View Answer Follow 1.2k

RecursionIntroduction of IndexersIntroduction of PropertiesProperties and its ApplicationsInterfaces IntroductionInterfaces ImplementationFundamentals of Exception HandlingImplementation of Exception HandlingExceptions of Type Finally and Built inTry & Catch in DetailAttributesIntroduction of Console I/O OperationsReading Console Input OperationsWriting Console Output OperationsIntroduction of Stream ClassesByte StreamCharacter StreamFundamental of DelegatesDelegates in DetailEventsFundamental of GenericsGeneric MethodsFundamental of LINQOperation and Query with LINQIntroduction of ReflectionsCollection ClassesMaths ClassRounding Functions in C#Math MethodsMulti-threaded Programming - 1Multi-threaded Programming - 2IteratorsFundamentals of NamespacesFundamentals of PreprocessorsMethod with ParametersFundamental of NetworkingURI classNetwork Errors HandlingType InterfaceUnsafe Code & Pointers Basics

Pointers Operation - 1Pointers Operation - 2Accessor Controls of ClassIntroduction of String FormattingString Formatting - 1String Formatting - 2

Follow Manish & Sanfoundry

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 5/13

View Answer

5. What will be the output of following snippet of code?

1. class number2. {3. private int num1 = 60;4. private int num2 = 20;5. public int anumber6. {7. get8. {9. return num1;

10. }11. set12. {13. num1 = value;14. }15. }16. public int anumber117. {18. get19. {20. return num2;21. }22. set23. {24. num2 = value;25. }26. }27. }28. class Program29. {30. public static void Main(string[] args)31. {

32. number p = new number();33. number k = new number();34. int m = p.anumber;35. int t = k.anumber1;36. int r = p.anumber * k.anumber1;37. Console.WriteLine("sum = " + r);38. Console.ReadLine();39. }40. }

a) 0

Follow 1.5k

Subscribe to Sanfoundry

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 6/13

b) 120c) 1200d) Compile time error

View Answer

6. What will be the output of following snippet of code?

1. class number2. {3. int length = 50;4. public int number15. {6. get7. {8. return length;9. }

10. set11. {12. length = value;13. }14. }15. }16. class Program17. {18. public static void Main(string[] args)19. {20. number p = new number();21. p.number1 = p.number1 + 40;22. int k = p.number1 * 3 / 9;23. Console.WriteLine(k);24. Console.ReadLine();25. }

26. }

a) 0b) 180c) 30d) Compile time error

View Answer

7. What will be the output of following snippet of code?

1. class number2. {3. int length = 60;4. public int number1

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 7/13

4. public int number15. {6. get7. {8. return length;9. }

10. }11. }12. class Program13. {14. public static void Main(string[] args)15. {16. number p = new number();17. int l;18. l = p.number1 + 40;19. int k = l * 3 / 4;20. Console.WriteLine(k);21. Console.ReadLine();22. }23. }

a) 30b) 75c) 80d) 0

View Answer

8. What will be the output of following snippet of code?

1. class student2. {3. int []scores = new int[5] {23, 42, 54, 11, 65};4. public int this[int index]5. {6. get7. {8. if (index < 5)9. return scores[index];

10. else11. {12. Console.WriteLine("invalid index");13. return 0;14. }15. }16. set17. {

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 8/13

18. if (index < 5)19. scores[index] = value;20. else21. Console.WriteLine("invalid index");22. }23. }24. }25. class Program26. {27. public static void Main(string[] args)28. {29. student s = new student();30. Console.WriteLine(s[4] + 8);31. Console.ReadLine();32. }33. }

a) 73b) 37c) 0d) Run time error

View Answer

9. Correct way to implement the property for which property reports theerror “invalid index” if user attempts to cross bounds of the array for astudent class with 5 intger arrays.a)

1. class student2. {3. int []scores = new int[5] {23, 42, 54, 11, 65};4. public int this[int index]5. {6. get7. {8. if (index < 5)9. return scores[index];

10. else11. {12. Console.WriteLine("invalid index");13. return 0;14. }15. }16. set17. {18. if (index < 5)19. scores[index] = value;20. else

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 9/13

20. else21. Console.WriteLine("invalid index");22. }23. }24. }

b)

1. class student2. {3. int []scores = new int[5] {23, 42, 54, 11, 65};4. public int this[int index]5. {6. get7. {8. if (index < 5)9. return scores[index];

10. else11. {12. Console.WriteLine("invalid index");13. return 0;14. }15. }16. }

17. }

c)

1. class student2. {3. int []scores = new int[5]{23, 42, 54, 11, 65};4. public int this[int index]5. {6. set7. {8. if (index < 5)9. return scores[index];

10. else11. {12. Console.WriteLine("invalid index");13. return 0;14. }15. }16. }17. }

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 10/13

17. }

d) None of the above mentionedView Answer

10. What will be the output of following snippet of code?

1. class student2. {3. int []scores = new int[3] {13, 32, 24};4. public int this[int index]5. {6. get7. {8. if (index < 3)9. return scores[index];

10. else11. {12. Console.WriteLine("invalid index");13. return 0;14. }15. }

16. private set17. {18. if (index < 3)19. scores[index] = value;20. else21. Console.WriteLine("invalid index");22. }23. }24. }25. class Program26. {27. public static void Main(string[] args)28. {29. student s = new student();30. int[] scores1 = new int[3] {8, 19, 40};31. for (int i = 0; i < 3; i++)32. {33. if (scores1[i] > s[i])34. {35. Console.WriteLine(" scores1 had greater value :" + scores1[i]);36. }37. else38. {39. Console.WriteLine("scores had greater value :" + s[i]);40. }

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 11/13

Advertisements

Subscribe Newsletter & Posts

40. }41. }42. Console.ReadLine();43. }44. }

a) 0b) Compile time errorc) Run time errord) scores had greater value : 13scores had greater value : 32scores1 had greater value : 40

View Answer

Sanfoundry Global Education & Learning Series – C# ProgrammingLanguage.Here’s the list of Best Reference Books in C# Programming Language.

To practice all features of C# programming language, here is complete

set on 1000+ Multiple Choice Questions and Answers on C#

0

Tweet

Hover to Expand

THERE WILL BE HATERS

Name

*Email Address

*

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 12/13

Read Next:1. C# Program to Demonstrate Properties of the Class2. C# Questions & Answers – Introduction of Properties3. C# Questions & Answers – Introduction of Indexers4. Python Questions and Answers – Files – 15. C# Questions & Answers – Implementation of Exception

Handling

Manish Bhojasia, a technology veteran with 17+ years @ Cisco &Wipro, is Founder and CTO at Sanfoundry. He is Linux KernelDeveloper and SAN Architect and is passionate aboutcompetency developments in these areas. He lives in Bangaloreand delivers focused training sessions to IT professionals in LinuxKernel, Linux Debugging, Linux Device Drivers, LinuxNetworking, Linux Storage & Cluster Administration, Advanced CProgramming, SAN Storage Technologies, SCSI Internals andStorage Protocols such as iSCSI & Fiber Channel. Stayconnected with him below.

Manish Bhojasia

1,289 followers

Follow

Sanfoundry

+ 1,539

Follow +1

Subscribe

*

2/25/2015 C# Questions & Answers - Properties and its Applications | Sanfoundry

http://www.sanfoundry.com/csharp-mcqs-properties-applications/ 13/13

Terms of Use & Privacy Policy Copyright Technology GroupsInterns Jobs Sitemap

Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel & Device Driver Programming. Our Founder has trainedemployees of almost all Top Companies in India. Here are few of them: VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft,Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium Networks, ST Microelectronics, Samsung, LG-Soft, Wipro, TCS, HCL, IBM,Accenture, HSBC, Northwest Bank, Mphasis, Tata Elxsi, Tata Communications, Mindtree, Cognizant, mid size IT companies and many Startups.Students from top Universities and colleges such as NIT Trichy, BITS Pilani, University of California, Irvine, University of Texas, Austin & PESITBangalore have benefited a lot from these courses as well. The assignments and real time projects for our courses are of extremely high qualitywith excellent learning curve.

Register for Expert Level Training Classes by our Founder & CTO. Alternatively, call us for your Corporate Training or College Trainingneeds.

© 2015 Sanfoundry ↑Responsive Theme powered by

WordPress

Practice Interview Questions & Answers, Quizzes, Objective,Multiple Choice Aptitude Tests for Freshers and ExperiencedPeople in these topics -

C, C++, C#, Java, Linux, SAN, Javascript, PHP, PythonOperating Systems, Computer Organization andArchitecture, Database Management Systems, SoftwareArchitecture & Design, Software Engineering, ArtificialIntelligence, LISP Programming, Computer Networks,Microprocessors

Learn C, C++, Java and C# Programming with coding exampleon Simple problems as well as tough Algorithms and Data-structures along with runtime output: - C Programs, Data-Structures and Algorithms, C++ Algorithms, Java Algorithms, C#

Programs, Android Programs in Java

C Tutorials and Linux Commands Tutorial - C Tutorials, LinuxCommands

Career Mentoring with our Founder / CTO - Read More