C# Final

Ace your homework & exams now with Quizwiz!

The value of (x++ + --y) - (++x + y--) is

-2

SOLID Principles

-Single Responsibility -Open Closed -Liskov Substitution -Interface Segregation -Dependency Inversion

Consider int[] v = { 23, 44, 78 }; int[] w = v; w[2] = 100; What is the value of v[2]?

100

Assume integer variables x=10, y=5, z=3, w=2. The value of x + y % w is 1 11 12 none of the above

11

If k has the value of 4, what value will the variable x have after executing? x = 2; switch(k) { case 3: case 4: x = 7; case 5: x = 8; case 8: x = 11; )

11

Assume integer variables x=10, y=5, z=3, w=2. The value of w *= y + z is 13 16 18 none of the above

16

What will the following program fragment output? int x=10, y=12, r; if (y > x) { int t = y; y = x; x = t; } while (y != 0) { r = x % y; x = y; y = r; } System.Console.WriteLine(x);

2

Which of the following express the same value? 2345e-2 0.0023450E3 0.23450 .02345E+3

2345e-2 .02345E+3

Which of the following is not a valid C# identifier? a_big_Car __STOP hat123 23skidoo none of the above

23skidoo

Find the value of the variable 'total' after the execution of the code: int i = 5; int total = 100; do { total -= i; i += 4; }while (i < 20);

56

Find the value of the variable total after the execution of the code int i = 5; int total = 100; do { total -= i; i += 4; }while ( i < 20);

56

How many times will the body of the while loop be executed if x has the value 11 at the start of the loop? while (x > 0) { System.Console.WriteLine(x); x -= 2; }

6

How many times will the body of the while loop be executed if x has the value of 11 at the start of the loop? while (x > 0) { System.Console.WriteLine(x); x -= 2; }

6

What is the value of y after the execution of the code int x = 5, y = 3; while (x < 20) { x += 4; y += x; }

63

What value will the variable sum have after the execution of the code int sum = 100; for(int j = 10; j > 7; j--) sum -= j;

73

What value will the variable 'sum' have after the execution of the code int sum = 50 for(int j = 2; j < 12; j +=3) sum += j;

76

What value will the variable sum have after the execution of the code int sum = 50 for(int j = 2; j <12; j += 3) sum += j;

76

What value will the variable x have after executing x = 9; if(k < 13) if(k < 7) x = 5; else x = 8; if k has the value 10?

8

Given String s = "Tuna fish"; find s.Length;

9

Class A has a method public void test() Classe B derives from A. Given the method public void tryIt(A anA) { anA.test(); } which of the following is correct, where myA is an object type A and myB has type B? a. both of the above b. none of the above c. tryIt(myA); d. tryIt(myB);

Both of the above

We use the _________________ method to determine if one String is alphabetically less than another.

CompareTo

High level modules should not depend on Low level modules. Both should contain abstractions. This is which SOLID principle ?

Dependency Inversion Principle (DIP)

_______________ is process of hiding implementation of data from outside world so that it can't made any changes to the data thus avoiding the disasters. This can be accomplished by making the data private because private data is accessible only inside a class not by the outside world

Encapsulation

What are the three (3) pillars of object oriented programming Abstraction Encapsulation Inheritance Polymporhism

Encapsulation Inheritance Polymporhism

___________ allows you to define a child class that reuses (inherits), extends, or modifies the behavior of a parent class. The class whose members are inherited is called the base class. The class that inherits the members of the base class is called the derived class.

Inheritance

Make fine grained interfaces that are client specific is an example of which SOLID principle ?

Interface Segregation Principle (ISP)

Derived classes must be substitutable for their base classes is an example of which SOLID principle ?

Liskov Substitution Principle (LSP)

You should be able to extend a classes behavior, without modifying it is an example of which SOLID principle

Open/Closed Principle (OCP)

____________ is a concept by which we can perform a single action by different- different ways

Polymorphism

A class should have only one reason to change" is an example of which SOLID principle?

Single Responsibility Principle (SRP)

Abstract classes cannot be instantiated T/F?

True

Abstract classes cannot be instantiated. True/False?

True

Interfaces contain no implementation details T/F?

True

In order to override a base class method, we must declare that base class method as a ______________ method

Virtual

What is the actual type of an object? a) The super class of an object b) The concrete class used to create the object c) The abstract class of an object d) The inheritance hierarchy of the object

a) The super class of an object

What does an interpreter do? a) run the program b) store the source code c) translate from one language to another d) none of the above

a) run the program

Given Polymorphism, which of the following is true? a. One variable can point to different types of objects b. Objects can behave differently depending on their type c. Both of the above d. None of the above

a. One variable can point to different types of objects

The code public class B : A { } a. defines a class that inherits all the methods of A b. will not compile because the body in empty c. none of the above d. defines a class that inherits the public methods of A only

a. defines a class that inherits all the methods of A

Which of the following is correct?. a. C# never requires the programmer to handle an exception. b. C# requires programmers to handle all exceptions. c. C# only requires exception handling in forms. d. C# requires the programmer to handle IO exceptions, but not others.

a. C# never requires the programmer to handle an exception.

An abstract class a. all of the above b. may contain constructors c. may extend another class d. may contain instance variables

all of the above

Given the declaration public static int ppp; the variable ppp is a) a constant b) a class variable c) an instance variable d) none of the above

b) a class variable

Which of the following, if any, are not valid in C# a) double d = 4; b) int i = 4.0; c) int i = (int) 4.7; d) double d = (double)5;

b) int i = 4.0

If class B derives from an abstract class A, which if the following is correct? a. none of the above b. A anA = new B(); c. A anA = new A(); d. B anB = new A();

b. A anA = new B();

In public Name(String f, char i, String l) : this(f,l) { initial = i; } the expression this(f,l) a. none of the above b. calls another Name constructor. c. calls the this method. d. calls the current constructor.

b. calls another Name constructor.

The code public class B : A { } defines a class B that a. is a base class of A b. is a derived class of A c. none of the above d. implements A

b. is a derived class of A

Inheritance reflects a. the DOES_A relationshop b. the IS_A relationship c. none of the above d. the HAS-A relationship

b. the IS_A relationship

Given the array int[][] x = {{2,3},{4,5},{6,7}}; x[1] is a. not defined b. {4,5} c. none of the above d. {2,3}

b. {4,5}

Assume Integer variables x=10, y =5, z=3, w=2. The value of x / z * y is... a) 16 2/3 b) 0 c) 15 d) None of the above

c) 15

What does a compiler do? a) run the program b) store the source code c) translate from one language to another d) none of the above

c) translate from one language to another

Which of the following adds 10 to every value in a 16-element integer array named points? a. For(int sub = 0; sub > 15; ++sub) points[sub] += 10; b. Foreach(int sub in points) points += 10; c. neither of these d. Both of these

c. neither of these

A C# interface can list a. methods and constants. b. methods, constants, and variables c. methods, constants, variables, and constructors. d. methods.

d. methods.

Which of the following correctly declares an array of four integers? a. Int[] ages = new int[4] {20, 30, 40, 50} b. Int[] ages = {20, 30, 40, 50}; c. Int[] ages = new int[] {20, 30, 40, 50}; d. All of these

d. All of these

Which of the following is not a C# exception? a. ApplicationException b. OutOfMemoryException c. FormatException d. RuntimeException

d. RuntimeException

Which of the following is not correct? a. int [] v; b. none of the above c. int v[]; d. int v[3];

d. int v[3];

Class B is derived from A. Class A has a method int x(int y) { ...} and class B has a method double x(double y) { ... } Does the method x in class B a. override the method x in class A? b. none of the above c. override and overload the method x in class A? d. overload the method x in class A?

d. overload the method x in class A

A constructor a) must have the same name as the class it is declared in b) is used to create objects c) may be overloaded d) b and c above e) all of the above

e) all of the above

Which of the following for statements computes the same value for sum as for (int x = 0; x < 15; x+=2) sum += x + 5;? a. none of the above b. for (int x = 5; x < 20; sum += x-2) x += 2; c. for (int x = 0; x < 15; sum += x+3) x += 2; d. for (int x = 5; x < 20; x+=2) sum += x; e. all of the above

e. all of the above

A constructor a. must have the same name as the class it is declared within. b. is used to create objects. c. may be overloaded. d. b and c above e. all of the above

e. all of the above

An object that has no references to it is termed _______________________.

garbage

If an exception occurs the program a. continues to the end of the current method and then jumps to a catch clause, if any. b. jumps immediately to a catch clause, if any, and continues after the catch clause, or aborts. c. jumps immediately to a catch clause, if any, and returns to finish the method code. d. continues to the end of the current method, and then aborts.

jumps immediately to a catch clause, if any, and continues after the catch clause, or aborts.

Given the declaration String abc; what is the value of the variable abc?

null

Defining two methods with the same name but with different parameters is called ________________________.

overloading

Declaring an instance variable using the _______________ modifier restricts its use to the methods of the class in which it is declared.

private

Given String s = "The three did feed the deer" find s[6]

r

Given String s = "potato"; find v where String v = s.Substring(2,3);

tat

The Common Language runtime manages _____________________.

the execution of code

In the body of a method, C# uses the variable named ______ to refer to the current object whose method is being invoking.

this


Related study sets

Chapter 4: The Market Forces of Supply & Demand

View Set

Chapter 16: Eye and Ear Diseases and Disorders.

View Set

Ch. 5 Adaptations to Anaerboic Training Programs

View Set

Accounting Final Connect CH. 8-10

View Set

س: مشارطة الإيجار بالرحلة من حيث تعريفها وطبيعتها القانونية وآثارها

View Set

Describing your school day in Spanish ESSENTIAL

View Set