Difference between revisions of "Interview Questions"

From Hawk Wiki
Jump to: navigation, search
(Virtual inheritance)
(Java)
 
(37 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==Some Translation==
 
==Some Translation==
n! Multiplicative
+
n! Factorial
 +
 
 
==Object-oriented programming==
 
==Object-oriented programming==
===Encapsulation===
+
Check here [[Interview_Questions(OOP)]]
restricting access to some of the object's components<br>
+
==C++ Interview==
bundling of data with the methods<br>
+
[[C++ interview]]
public and private data and methods.<br>
+
==Javascript/Jquery==
A benefit of encapsulation is that it can reduce system complexity, and thus increases robustness, reduce risk of conflict between components.<br>
+
[[AJAX&Jquery]]<br>
=== Polymorphism ===
+
[http://{{SERVERNAME}}/downloads/designpattern/ Design Pattern]
In C++, that type of polymorphism is called overloading.
+
If a class has inherited a parent class, it can redefine a method and thus each class has a method with the same name but different functionality.
+
===Inheritance===
+
Inheritance is a way to reuse code of existing objects, establish a subtype from an existing object.<br>
+
Allow replace the implementation of an inherited method or data.<br>
+
===Public Private Protected===
+
A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class<br>
+
A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes<br>
+
A member (either data member or member function) declared in a public section of a class can be accessed by anyone<br>
+
===Private Inheritance===
+
Private inheritance is like making a composition.<br>
+
One advantage to using protected/private inheritance instead of composition is that the derived class has access to protected members in the parent class. However this is kind of a double-edged sword, as it becomes easier to misuse the class.
+
<pre>
+
class Motherboard {};
+
 
+
// this makes a "has a" relationship
+
class Computer : private Motherboard
+
{
+
};
+
 
+
// this makes a similar "has a" relationship
+
//  this approach is aka "composition"
+
class Computer
+
{
+
private:
+
  Motherboard mobo;
+
};
+
</pre>
+
===Virtual Functions===
+
If the function is designated virtual in the base class then the derived class' function would be called (if it exists). If it is not virtual, the base class' function would be called.
+
To be short, virtual functions will have lowest priority to be called.
+
===Virtual inheritance===
+
To avoid ambiguous call of the same 2 levels higher base class. Declare virtual to say that the 2 levels higher base class is the same shared one.
+
<pre>
+
class Animal {
+
public:
+
  virtual void eat();
+
};
+
+
// Two classes virtually inheriting Animal:
+
class Mammal : public virtual Animal {
+
public:
+
  virtual void breathe();
+
};
+
+
class WingedAnimal : public virtual Animal {
+
public:
+
  virtual void flap();
+
};
+
+
// A bat is still a winged mammal
+
class Bat : public Mammal, public WingedAnimal {
+
};
+
</pre>
+
To avoid ambiguous between inherited WingedAnimal::Animal and Mammal:Animal
+
From the code above.Animal instance is unambiguous,and we can call Bat::eat().
+
===Virtual const===
+
<pre>
+
class Base
+
{
+
public:
+
    virtual void eval() const
+
    {
+
        std::cout<<"Base Const Eval\n";
+
    }
+
};
+
 
+
class Derived:public Base
+
{
+
public:
+
    void eval()
+
    {
+
        std::cout<<"Derived Non-Const Eval\n";
+
    }
+
};
+
int main()
+
{
+
  
    Derived d;
+
==Algorithm Interview Problems==
    Base* pB=&d;
+
[[Algorithm Problems]]<br>
 +
==Data Structure==
 +
[[All about Binary search tree]]<br>
 +
[[All about Linked List]]<br>
 +
[[Heap & Heap Sort]]<br>
 +
[[TRIE]]<br>
 +
[[Algorithm Sorting]]<br>
  
    pB->eval(); //This will call the Base eval()
+
==Regular Expression ==
 +
http://www.zytrax.com/tech/web/regex.htm
  
    return 0;
+
==PHP==
}
+
[[PHP interview]]
</pre>
+
==Java==
The example above. based class evel() will be called.
+
[[Java interview]]
In your Derived class, the prototype for eval doesn't match the one for the virtual function in Base. So it won't override the virtual function.
+
==Python==
If you add the const for Derived::eval(), you should get virtual behavior.
+
[[Python interview]]

Latest revision as of 00:27, 17 March 2015

Some Translation

n! Factorial

Object-oriented programming

Check here Interview_Questions(OOP)

C++ Interview

C++ interview

Javascript/Jquery

AJAX&Jquery
Design Pattern

Algorithm Interview Problems

Algorithm Problems

Data Structure

All about Binary search tree
All about Linked List
Heap & Heap Sort
TRIE
Algorithm Sorting

Regular Expression

http://www.zytrax.com/tech/web/regex.htm

PHP

PHP interview

Java

Java interview

Python

Python interview