Interview questions for Java Oops
1. Why OOP is so popular?
OOPs, programming paradigm is considered as a better style of programming. Not only it helps in writing a complex piece of code easily, but it also allows users to handle and maintain them easily as well. Not only that, the main pillar of OOPs – Data Abstraction, Encapsulation, Inheritance, and Polymorphism, makes it easy for programmers to solve complex scenarios. As a result of these, OOPs is so popular.
2. What is Pure.CSS?
Pure.CSS is a Cascading Style Sheet (CSS) framework developed by Yahoo. It is used to make website faster, beautiful and responsive.
3. Which are the important features of Pure.CSS?
o It is free.
o It has in-built responsive designing.
o It uses satandard CSS with minimal footprint.
o It is a collection of small, responsive CSS modules.
o It supports shadow and bold colors.
o The colors and shades remain uniform across various platforms and devices.
4. What are the advantages and disadvantages of OOP?
Advantages of OOP
o It follows a bottom-up approach.
o It models the real word well.
o It allows us the reusability of code.
o Avoids unnecessary data exposure to the user by using the abstraction.
o OOP forces the designers to have a long and extensive design phase that results in better design and fewer flaws.
o Decompose a complex problem into smaller chunks.
o Programmer are able to reach their goals faster.
o Minimizes the complexity.
o Easy redesign and extension of code that does not affect the other functionality.
Disadvantages of OOP
o Proper planning is required.
o Program design is tricky.
o Programmer should be well skilled.
o Classes tend to be overly generalized.
5. What is Pure.CSS grids?
PURE.CSS provides concept of Pure Grid with two types of classes:
o pure-g: A grid class
o pure-u-*: A unit class
6. How do you Pure.CSS grid?
Following are the rules to use Pure.CSS Grids:
o Widths of Units are in fractions. For example, pure-u-1-2 represents 1/2 or 50% width, pure-u-2-5 represents 2/5 or 40% width and so on.
o Children of Pure Grid (element with pure-g class) must be using pure-u or pure-u-* classnames.
o All content should be a part of a grid unit to be rendered properly.
7. What do you mean by the term extensible in Pure.CSS?
Pure is elegant, simple, and lightweight. It is very easy to work with. The biggest advantage of using Pure CSS is it is built to be extensible. You can simply add a few styles in your own CSS and change the look to your website.
8. Give the definition of “method”?
A method is a sequence of commands that are invoked by a specific name. We can say that this is a function and a procedure (in the case of the void method).
9. What is a method signature?
The method signature in Java is the name of the method plus the parameters (and the order of the parameters matters).
The method signature does not include the return value, the exceptions thrown by it, or modifiers.
Keywords public, protected, private, abstract, static, final, synchronized, native, strictfp incl. annotations for the method are modifiers and are not part of the signature.
10. What methods are called overloaded?
Java allows you to create multiple methods with the same name, but different signatures. Creating a method with the same name but with a different set of parameters is called overloading. Which of the overloaded methods should be executed when invoked, Java determines based on the actual parameters.
11. What is inheritance?
Inheritance allows a Child class to inherit properties from its parent class. In Java this is achieved by using extends keyword. Only properties with access modifier public and protected can be accessed in child class.
12. What do you understand by pure object-oriented language? Why Java is not a pure object-oriented programming language?
The programming language is called pure object-oriented language that treats everything inside the program as an object. The primitive types are not supported by the pure OOPs language. There are some other features that must satisfy by a pure object-oriented language:
o All predefined types are objects
o All user-defined types are objects
o All operations performed on objects must be only through methods exposed to the objects.
Java is not a pure object-oriented programming language because pre-defined data types in Java are not treated as objects. Hence, it is not an object-oriented language.
13. What is multiple inheritance and does java support?
If a child class inherits the property from multiple classes is known as multiple inheritance. Java does not allow to extend multiple classes. The problem with the multiple inheritance is that if multiple parent classes have methods with same name, then at runtime it becomes difficult for the compiler to decide which method to execute from the child class. To overcome this problem java allows to implement multiple Interfaces. The problem is commonly referred as What is Diamond Problem.
14. What is Association?
Association is a relationship where all object have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with a single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently
15. What is Aggregation?
Aggregation is a specialized form of Association where all objects have their own lifecycle but there is ownership and child object can not belongs to another parent object. Let’s take an example of Department and teacher. A single teacher cannot belong to multiple departments, but if we delete the department teacher object will not destroy. We can think about “has-a” relationship.
16. What is Abstraction?
Abstraction is a concept of showing only important information and hiding its implementation.This is one of the most asked Oops interview questions as it checks basic oops concepts for java programmers.
When you see a car, you know it is running but how it running internally, you may not aware of it.
This is Abstraction. You just expose required details.
17. What is encapsulation?
Encapsulation is process of wrapping data and function into single unit. You can use access modifier for variables, so other classes may not access it directly but it can be accessed only through public methods of the class. You can create class fully encapsulated using private variables.
What are types of Polymorphism in java?
There are two type of polymorphism in java.
• Compile time polymorphism
• Run time polymorphism
18. What are ways by which you can implement polymorphism in java?
You can implement polymorphism using
• Method overloading
• Method overriding