General OOP and Programming

Ace your homework & exams now with Quizwiz!

What is polymorphism?

(many changing) At run time, objects of a derived class may be treated as objects of a base class such as in method parameters, collections or arrays. Think of the dog, spider, and human example and implementing a "walk" method. What is an abstract base class? - Class that cannot be instantiated and is meant to provide a common definition of a base class that multiple derived classes can share.

What is the difference between an object and a class?

A class is a template to create an object and cannot be instantiated. An object can be instantiated and operated on.

What is a class?

A class is essentially a blueprint for creating objects. It describes the state (member variables) and behavior (member functions/methods).

What is a constructor?

A method which is executed when its object is created.

Difference between reference and value?

A reference contains the address of an object. A value contains an actual value. MORE INFORMATION

What is abstraction?

Abstraction is when one is only concerned with the behavior and not the implementation. This means that the user is only shown the relevant data and behaviors while the unnecessary details are hidden away. A good example of this could be operating a motor vehicle.

What is inheritance?

Allows you to create new classes that can reuse, extend, and modify behavior defined in other classes. The class whose members are inherited is called the base class, the class that inherits is called the derived class. A derived class (in C#) can only have one direct base class; however, inheritance is transitive. For example American shorthair inherits from cat which inherits from animal. An American shorthair is a cat but is also an animal.

What is the difference between an interface and an abstract class?

An interface allows can inherit for multiple sources an abstract class cannot.

What is an object?

An object is an instantiated "thing" that has a type which defines what data and behaviors the object has. An object is a block of memory that has been allocated and configured according to a class (blueprint).

What is an interface?

Contains definitions for a group of related functionalities that a class or struct can implement. Interfaces can include behavior from multiple sources in a class. It cannot be instantiated directly and contains no implementation of methods.

What is a virtual method?

It allows a method to be overridden in a derived class.

Is it legal to call a virtual method from within a constructor? (C#)

It might compile but it will throw an error. This is because an object's base constructor is called before its own constructor.

When would you want to use an abstract class vs an interface?

When we talk about abstract classes we are defining characteristics of an object type; specifying what an object is. When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about what the object can do.

Can constructors be overloaded? Why would you want to do this?

Yes, they can.

Can a constructor be private?

Yes, this prevents a class from being instantiated. This would be used when creating a utility class.

What are generics?

Make it possible to design classes and methods that defer the specification of one or more parameter types until the class or method is declared and instantiated by client code. Use generic types to maximize code reuse, type safety, and performance. The most common use of generics is to create collection classes.

Can a static method contain non static members?

No.

What is OOP and why use it?

Object oriented programming is a way to describe what an object (thing) is and what it can do. Three of the main qualities that make OOP useful are: polymorphism, encapsulation, and inheritance. We use it because it makes it may make code easier to think about, better organize, and more maintainable.

Explain the difference between overriding and overloading a method.

Overriding is when a derived class is giving a definition to a virtual function in the base class. The derived class redefines the method. Overloading is when there are multiple methods in the same scope with the same name but different signatures.

What is the difference between public, static and void?

Public is an access modifier. Static defines whether a class or function is connected to an instance of a class (dynamic) or connected to the class as a whole (static). Void is the return type (meaning that the function should return nothing)

What is the differences among public, protected, internal and private?

Public, access is not restricted. Protected, access is limited to the contain class or types derived from the containing class. Internal, access limited to the current assembly. Private, access is limited to the containing type. Namespaces have no access restrictions.

What is encapsulation?

This is the process of containing data and functions into a single unit called a class. Encapsulation is often used so we do not directly access the variables. We access them using functions inside the class. Encapsulation makes data hiding possible.


Related study sets

Module 4—International Distribution: UNIT 1 MODES OF TRANSPORTATION

View Set