technical interview Flashcards
study for technical interview on the 12th at 12
Encapsulation
is a concept of hiding data by wrapping up members into a single unit such as a Class. It provides security to data members by making the variable private, and then creating public getter/setter methods to access those variables.
Inheritance
the ability of creating a new class from an existing class. Inheritance is when an object acquires the property of another object. Inheritance allows a class (subclass) to acquire the properties and behavior of another class (super-class). It helps to reuse, customize and enhance the existing code.
Abstraction
concept that focuses on hiding the complexity of a system by presenting a simpler interface
Polymorphism
Stems from Inheritance. A subclass can define its own unique behavior and still share the same functionalities or behavior of its parent/base class. A subclass can have their own behavior and share some of its behavior from its parent class not the other way around. A parent class cannot have the behavior of its subclass.
Getters (Accessors)
These methods are used to retrieve or access the value of an object’s private variables. Instead of directly accessing the variable, you use a getter method which returns the value of the variable. This approach allows the encapsulation of the variable, as it can only be accessed through the method, and not directly, maintaining the integrity and security of the data.
Setters (Mutators)
Conversely, setter methods are used to set or update the value of an object’s private variables. Instead of modifying the variable directly, you pass the value you want to set to the setter method, which then assigns the value to the variable. This allows for data validation or additional logic to be executed before the variable is modified, ensuring that the object remains in a valid or consistent state.
Access Control
a mechanism that manages access to the classes, methods, and variables. It determines how and who can access different parts of your program, ensuring that sensitive information is hidden from users and prevents unauthorized access.
Access Modifiers
- (public, private, protected): restricts visibility to class members; can be applied to class, methods, variables, and constructors; No modifier is also called default or package private.
public: accessible from anywhere.
protected: accessible within package and subclasses.
no modifier: only accessible within package.
private: only accessible within class.
Class Binding
refers to the time at which a method or variable is associated with a class or object. Includes Static Binding (Early Binding) and Dynamic Binding (Late Binding).
Static Binding: Method execution determined at compile time, used for private, final, or static methods.
Dynamic Binding: Method execution determined at runtime, crucial for polymorphism.
Inheritance
the ability of creating a new class from an existing class. Inheritance is when an object acquires the property of another object. Inheritance allows a class (subclass) to acquire the properties and behavior of another class (super-class). It helps to reuse, customize and enhance the existing code.
Hierarchical inheritance
form of inheritance where one superclass is inherited by multiple subclasses. Imagine a tree with branches; at the top is the parent class, and branching out from it are several child classes. Each child class inherits from the same parent but is separate from its siblings. For example, a Vehicle class could be the parent, with Car, Bike, and Truck as child classes, each inheriting from Vehicle but not from each other.
Parent Class vs. Child Class
Parent Class (Superclass): The class whose features are inherited. It’s the “base” or “super” class.
Child Class (Subclass): The class that inherits from the parent class. It can add its own unique attributes and methods in addition to what it inherits.
Interfaces
contracts that define what a class can do without specifying how it does it. They’re like a checklist (e.g., a “to-do” list) for a class. Any class that implements an interface agrees to perform the tasks on the list. Uses the word ‘implements’ before listing the interfaces a class would use.
Abstract classes
classes that cannot be instantiated on their own and are designed to be extended. They can have both fully implemented methods and abstract methods (without bodies). Think of an abstract class as a template for other classes.
Abstract Methods
methods declared in an abstract class without an implementation. Subclasses are required to provide implementations for these methods. It’s like a rule saying, “If you choose to be this type of thing, you must be able to do these actions.”
Constructors
special methods used to initialize new objects. Think of it as setting up a new phone; a constructor sets up the initial state.
Default Constructors
constructors that take no arguments. If you don’t define any constructor in your class, most languages provide a default one that helps to create an object with default settings.
Polymorphism
Stems from Inheritance. A subclass can define its own unique behavior and still share the same functionalities or behavior of its parent/base class. A subclass can have their own behavior and share some of its behavior from its parent class not the other way around. A parent class cannot have the behavior of its subclass.
Method Overriding
when a subclass provides a specific implementation for a method that is already defined in its superclass. It’s like customizing the functionality of an inherited method.
Method Overloading
when multiple methods in the same class have the same name but different parameters. It’s like having different versions of a tool, each version doing a slightly different job based on what you need.
Runtime vs Compile-time
Runtime: Decisions made during the program’s execution, like dynamic binding.
Compile-time: Decisions made by the compiler before the program runs, like static binding.
Covariance vs Contravariance
Covariance and Contravariance deal with how the type of objects can be assigned in a hierarchy, affecting polymorphism and generic types. Covariance allows assignment from a subclass to a superclass, while contravariance is the opposite… How Java handles overridden methods.
Classes
blueprints for creating objects. Each object created from a class can have its own set of attributes and behaviors defined by the class.
Properties
characteristics of an object, like color or size. In programming, properties are often implemented as variables within a class.
Parameters
Parameters - variables that are used to pass data into methods and constructors.
Relational Model (RM) – (Tables, Columns, Rows)
Tables, Columns, Rows: The foundation of relational databases, where data is organized into tables (relations), columns (attributes), and rows (records).
1:1 (One-to-One)
Each row in Table A is linked to no more than one row in Table B, and vice versa. Example: Each person has only one passport, and each passport is assigned to only one person.
1:M (One-to-Many)
Each row in Table A can be linked to many rows in Table B, but each row in Table B is linked to only one row in Table A. Example: A mother can have many children, but each child has only one mother.
M:N (Many-to-Many)
Rows in Table A can be linked to many rows in Table B, and rows in Table B can also be linked to many rows in Table A. This relationship often requires a third table (junction table) to manage the relationships. Example: Students and courses where students can enroll in many courses, and each course can have many students enrolled.