Computer Science Interview Questions

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is multiple inheritance? What are its advantages and disadvantages?

"Multiple inheritance is the process where a subclass can be derived from more than one super-class. Its advantage is that a class can inherit the functionality of more than one base class, but its disadvantage is that it can lead to a lot of confusion when two base classes implement a method with the same name."

. How Many Ways Are There To Initialize An Int With A Constant?

2 int a = 2; int a(2)

What is a class

A blueprint for which objects are created. It has methods and variables associated with the instance of the class

C++ What Is A Constructor? A Destructor?

A constructors and destructors are methods defined in a class that are invoked automatically when an object is created or destroyed. They are used to initialize a newly allocated object and to cleanup behind an object about to be removed.

what is a conversion constructor

A conversion constructor is a single-parameter constructor that is declared without the function specifier explicit. The compiler uses conversion constructors to convert objects from the type of the first parameter to the type of the conversion constructor's class.

what is a default constructor

A default constructor is a constructor which can be called with no arguments (either defined with an empty parameter list, or with default arguments provided for every parameter).

What is a file

A named location that stores data or information permanently. It usually has a primary and secondary name separated by a dot.

What is a stream?

A stream can be defined as the sequence of data. There is two type of streams. InputStream: Used to read a data from a source. OutPut Stream: Used to write a data into a destination.

What Are The Differences Between A C++ Struct And C++ Class?

A struct and a class are almost exactly the same with the only difference being if you don't specify visibility (protected, public, private) in a struct things will be public whereas in a class things will be private

what is an object

An object is an instance of a class

What Is A Virtual Destructor?

I think it deal with using delete. when you make a virtual base class destructor it will make all derived class destructors virtual as well

what is a superclass

In object-oriented programming, a class from which other classes inherit code is called a superclass, and the class which inherits the code is called a subclass of that superclass.

What are multiple inheritances in Java?

Java supports multiple inheritances i.e the ability of a class to implement more than one interface. A class can implement multiple Interfaces but cannot extends multiple classes.

How Is Memory Allocated/deallocated In C ? How About C++ ?

Memory is allocated in C using malloc() and freed using free(). In C++ the new() operator is used to allocate memory to an object and the delete() operator is used to free the memory taken up by an object.

Difference between overloading and overriding?

Overloading is when two or more methods in the same class have the same method name but different parameters(i.e different method signatures). Overriding is when two methods having the same method name and parameters (i.e., method signature) but one of the methods is in the parent class and the other is in the child class

contrast procedural and object oriented programming

Procedural programming is akin to making a recipe, everthing is step by step manipulation of data items. Object oriented programing is combining your data and the methods that operate on that data into a single package. you hav objects that are defined by classes . its sort of like writing a play where the attributes are characters and you have to first define their personalities and then you can write the dialogue and as a result get the drama.

What Are The Access Privileges In C++ ? What Is The Default Access Level ?

The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and it's sub-classes. Public members of a class can be accessed by anyone.

what is the difference between equals() and ==

The equals() is a method and it matches the content of the strings whereas == is an operator and matches object or reference of the strings.

What Is Cin And Cout?

They are objects corresponding to a program's default input and output files.

what is polymorphism

This means many forms and it is the ability for a object to take on many forms. for examle an integer is polymorphic, its reltively generic but when the code is complied its exact type will be determined.

Explain The Scope Resolution Operator.?

With this always think :: It can be used for about 4 different things 1. to access global variables when there is a local variable with the same name 2. to define a function outside of a class 3. to access a class's static variables 4. and can be used in the case of multiple inheritance where a variable name exists in two ancestor classes, the scope resolution operator can be used to distinguish

constructor vs method

a constructor is used to initialize some object and does not have a return type a method is used to perform some operation and does have a return type

what is a "is a" relationship vs a "has a" relationship

a is a realationship "is a" class that is a specialization of another one. for example you could have a class named dog and animal. a dog is a animal just more specialized. the "has a" relationship is when a class has a instance of another class. for example an employee has a salary.

what is a constructor

a method that can be used to create an object of a class. There are 2 types of constructors default and parameterized

what does const mean

a objects value cant be changed

what is an array

an array is a fixed size container that holds inforamtion of the same type

What Is An Instance?

an object that is a member of some class

what is encapsulation

bundling variables and methods into one unit like a class, so your bundling the data with the methods that operate on that data. With encapsulation data cant be aaccesed directly by outside parties but only through the public functions available in the class. esentailly attributes are kept private and you have public getter and setter functions available to manipulate those attributes. encapsualtion is what makes the concept of data hiding possible

how do you create an object

decalare instatiate declare box box1; //where box is the class

what are the 4 basics principles of object oriented programming

encapsulation abstraction inheritance polymorphism

what are templates

generic programming. they allow us to write code independent of types. we can do this by creating generic classes or functions using templates.

what is object oriented programming

its a programming language where everything is revolving around objects and data. and you can then crete realtionships betwen differnet objects

what is inheritance

its when the properties of the parent class are passed on to the child class

When Should You Use Multiple Inheritance?

never, its messy. only as a last resort

what is a base class

the parent class of a derived class

which operator has the highest precedence in java

the post fix operator (), []

When Is A Template A Better Solution Than A Base Class?

when perhaps the types might become an issue

what is a singleton class

with a singleton class you are only allowed to create 1 object for that class, but it does give you to flexibility to create more objects if the situation changes.

whats the diffence between class and instance variables

with instance variables the varaibles belong to that instnace or object and changes made to that variable what affect other instances. With class variables there is only one of those variables and they are shared amongst all of the instances

Is string class final?

yes

what are the differnt type of access modifyers

• Visible to the overall package. No modifier needed. • Private - Visible to class only. • Public - Visible to the world. • Protected - Visible to package and subclass.

What Is The Difference Between A Shallow Copy And A Deep Copy?

Because C++ does not know much about your class, the default copy constructor and default assignment operators it provides use a copying method known as a memberwise copy (also known as a shallow copy). This means that C++ copies each member of the class individually (using the assignment operator for overloaded operator=, and direct initialization for the copy constructor). When classes are simple (e.g. do not contain any dynamically allocated memory), this works very well.However, when designing classes that handle dynamically allocated memory, memberwise (shallow) copying can get us in a lot of trouble! This is because shallow copies of a pointer just copy the address of the pointer -- it does not allocate any memory or copy the contents being pointed to! Deep copying One answer to this problem is to do a deep copy on any non-null pointers being copied. A deep copy allocates memory for the copy and then copies the actual value, so that the copy lives in distinct memory from the source. This way, the copy and source are distinct and will not affect each other in any way. Doing deep copies requires that we write our own copy constructors and overloaded assignment operators.

What is the difference between C and C++ ?

C++ supports the object-oriented programming paradigm while C is based on structured programming.

T/F constructors can be virtual

F

What is the necessity & advantages of OOPS?

Troubleshooting When working with object-oriented programming languages, you know exactly where to look. "Oh, the car object broke down? The problem must be in the Car class!" You don't have to muck through anything else. That's the beauty of encapsulation. Objects are self-contained, and each bit of functionality does its own thing while leaving the other bits alone. Also, this modality allows an IT team to work on multiple objects simultaneously while minimizing the chance that one person might duplicate someone else's functionality. 2. Reuse of code through inheritance Suppose that in addition to your Car object, one colleague needs a RaceCar object, and another needs a Limousine object. Everyone builds their objects separately but discover commonalities between them. In fact, each object is really just a different kind of Car. This is where the inheritance technique saves time: Create one generic class (Car), and then define the subclasses (RaceCar and Limousine) that are to inherit the generic class's traits. Riffing on this example, you now need just a few drivers, or functions, like "driveCar," driveRaceCar" and "DriveLimousine." RaceCarDrivers share some traits with LimousineDrivers, but other things, like RaceHelmets and BeverageSponsorships, are unique. This is where object-oriented programming's sweet polymorphism comes into play. Because a single function can shape-shift to adapt to whichever class it's in, you could create one function in the parent Car class called "drive" — not "driveCar" or "driveRaceCar," but just "drive." This one function would work with the RaceCarDriver, LimousineDriver, etc. In fact, you could even have "raceCar.drive(myRaceCarDriver)" or "limo.drive(myChauffeur)." 4. Effective problem solving A language like C has an amazing legacy in programming history, but writing software in a top-down language is like playing Jenga while wearing mittens. The more complex it gets, the greater the chance it will collapse. Meanwhile, writing a functional-style program in a language like Haskell or ML can be a chore. Object-oriented programming is often the most natural and pragmatic approach, once you get the hang of it. OOP languages allows you to break down your software into bite-sized problems that you then can solve — one object at a time.

What Is Uml?

UML refers to Unified Modeling Language. It is a language used to model OO problem spaces and solutions.


Conjuntos de estudio relacionados

Path Ch1/2 Cellular Responses to Stress and Toxic Insults: Adaptation, Injury, and Death

View Set

Ch 21 PrepUs: Antidepressant Agents

View Set

Chapter 15: the Lymphatic & Immune System

View Set

Starting Out with Java From Control Structures through Data Structures Test #2 - Chapter 4

View Set

ISBB Chapter 4 - Data and Databases

View Set

olecranon bursitis , repetitive strain injury ,Epicondylitis, De Quervain’s tenosynovitis i

View Set