Question:- What is the difference between new and override?
Answer:- The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function. • virtual: indicates that a method may be overridden by an inheritor • override: Overrides the functionality of a virtual method in a base class, providing different functionality. • new: Hides the original method (which doesnt have to be virtual), providing different functionality. This should only be used where it is absolutely necessary. When you hide a method, you can still access the original method by upcasting to the base class. This is useful in some scenarios, but dangerous.
Question:- Explain overloading and overriding with example?
Answer:- • Overloading Overloading is a concept in OOP when two or more methods in a class with the same name but the method signature is different. It is also known as compile-time polymorphism. For example, in the following code snippet, the method add() is an overloaded method. • Overriding If a method with the same method signature is presented in both child and parent class is known as method overriding. The methods must have the same number of parameters and the same type of parameter. It overrides the value of the parent class method. It is also known as runtime polymorphism. For example, consider the following program.
Question:- What is Cohesion in OOP?
Answer:- In OOP, cohesion refers to the degree to which the elements inside a module belong together. It measures the strength of the relationship between the module and data. In short, cohesion represents the clarity of the responsibilities of a module. It is often contrasted with coupling. It focuses on a how single module or class is intended. Higher the cohesiveness of the module or class, better is the object-oriented design. There are two types of cohesion, i.e. High and Low. • High cohesion is associated with several required qualities of software including robustness, reliability, and understandability. • Low cohesion is associated with unwanted qualities such as being difficult to maintain, test, reuse, or even understand. High cohesion often associates with loose coupling and vice versa.
Question:- Give a real-world example of polymorphism?
Answer:- The general meaning of Polymorphism is one that has different forms. The best real-world example of polymorphism is a person that plays different roles at different palaces or situations. • At home a person can play the role of father, husband, and son. • At the office the same person plays the role of boss or employee. • In public transport, he plays the role of passenger. • In the hospital, he can play the role of doctor or patient. • At the shop, he plays the role of customer.
Question:- What is the difference between a base class and a superclass?
Answer:- The base class is the root class- the most generalized class. At the same time, the superclass is the immediate parent class from which the other class inherits.
Question:- What is data abstraction and how can we achieve data abstraction?
Answer:- It is one of the most important features of OOP. It allows us to show only essential data or information to the user and hides the implementation details from the user. A real-world example of abstraction is driving a car. When we drive a car, we do not need to know how the engine works (implementation) we only know how ECG works. There are two ways to achieve data abstraction • Abstract class • Abstract method
Question:- What are the levels of data abstraction?
Answer:- There are three levels of data abstraction: • Physical Level: It is the lowest level of data abstraction. It shows how the data is actually stored in memory. • Logical Level: It includes the information that is actually stored in the database in the form of tables. It also stores the relationship among the data entities in relatively simple structures. At this level, the information available to the user at the view level is unknown. • View Level: It is the highest level of data abstraction. The actual database is visible to the user. It exists to ease the availability of the database by an individual user.
Question:- What are the types of variables in OOP?
Answer:- There are three types of variables: 1. Instance Variable: It is an object-level variable. It should be declared inside a class but must be outside a method, block, and constructor. It is created when an object is created by using the new keyword. It can be accessed directly by calling the variable name inside the class. 2. Static Variable: It is a class-level variable. It is declared with keyword static inside a class but must be outside of the method, block, and constructor. It stores in static memory. Its visibility is the same as the instance variable. The default value of a static variable is the same as the instance variable. It can be accessed by calling the class_name.variable_name. 3. Local Variable: It is a method-level variable. It can be declared in method, constructor, or block. Note that the use of an access modifier is not allowed with local variables. It is visible only to the method, block, and constructor in which it is declared. Internally, it is implemented at the stack level. It must be declared and initialized before use. Another type of variable is used in object-oriented programming is the reference variable. 4. Reference Variable: It is a variable that points to an object of the class. It points to the location of the object that is stored in the memory.
Question:- Is it possible to overload a constructor?
Answer:- Yes, the constructors can be overloaded by changing the number of arguments accepted by the constructor or by changing the data type of the parameters.
Question:- Can we overload the main() method in Java also give an example?
Answer:- es, we can also overload the main() method in Java. Any number of main() methods can be defined in the class, but the method signature must be different.
Question:- Consider the following scenario: If a class Demo has a static block and a main() method. A print statement is presented in both. The question is which one will first execute, static block or the main() method, and why?
Answer:- JVM first executes the static block on a priority basis. It means JVM first goes to static block even before it looks for the main() method in the program. After that main() method will be executed.
Question:- What is Node.js?
Answer:- Node.js is Server-side scripting which is used to build scalable programs. It is a web application framework built on Google Chromes JavaScript Engine. It runs within the Node.js runtime on Mac OS, Windows, and Linux with no changes. This runtime facilitates you to execute a JavaScript code on any machine outside a browser.
Question:- Is Node.js free to use?
Answer:- Yes. It is released under MIT license and is free to use.
Question:- Is Node a single threaded application?
Answer:- Yes. Node is a single-threaded application with event looping.
