Interview questions Flashcards
What is encapsulation ?
Encapsulation in Java is a process of wrapping code and data together into a single unit.
Example: Creating a fully encapsulated class in Java by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it.
How do you select all tables and rows in SQL, what query?
SELECT * FROM table_name
Explanation:
using “*” after “SELECT” fetches all the fields available from the identified table.
What is the difference between == and ===?
== in JavaScript is used for comparing two variables, but it ignores the datatype of variable. === is used for comparing two variables, but this operator also checks datatype and compares two values
What is polymorphism? Explain and give an example.
Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
Any Java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object.
What is abstraction? Explain and give an example.
Abstraction is a process of hiding the implementation details and showing only functionality to the user.
Another way, it shows only essential things to the user and hides the internal details, for example, sending SMS where you type the text and send the message. You don’t know the internal processing about the message delivery.
What is the relationship between a class and an object?
class: a class describes the contents of the objects that belong to it: it describes an aggregate of data fields (called instance variables), and defines the operations (called methods).
object: an object is an element (or instance) of a class; objects have the behaviors of their class. The object is the actual component of programs, while the class specifies how instances are created and how they behave.
What is a string? Explain and give an example.
A string is a data type, such as an integer and floating point unit, but is used to represent text rather than numbers.
For example, the word “orange” and the phrase “The sky is blue” are both strings. … Even “12345” could be considered a string.
What is inheritance? Explain and give an example.
Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object.
class Employee{ float salary=40000; } class Programmer extends Employee{ int bonus=10000; } } Programmer is the subclass and Employee is the superclass. The relationship between the two classes is Programmer IS-A Employee. It means that Programmer is a type of Employee and therefore Programmer inherits all the properties and behaviors of a parent object.
What is the difference between an array and an array list?
Array is a fixed length data structure whereas ArrayList is a variable length Collection class. We cannot change length of array once created in Java but ArrayList can be changed.
What is HTML and provide a list of tags?
Hyper text markup language
some tags: p, a, ul, ol, head, body, header, footer, strong, u, em
How do you declare a variable in JavaScript?
You declare a JavaScript variable with the var keyword: var varName and after the declaration, the variable has no value (technically it has the value of undefined ). An equal sign is used to assign values to variables.
What is the purpose of CSS?
CSS describes how HTML elements are to be displayed on screen, paper, or in other media
What is a loop? List them.
A loop statement allows us to execute a statement or group of statements multiple times.
Loops:
for
while
do..while
What is a conditional statement?
An expression that only executes if the given condition is true
What is a do-while loop?
The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.