Skip to main content

Abstraction Interview Questions in Java



Most Frequently asked Interview Questions and Answer in Java:


           In this Java Interview Question blog, we have covered almost total 100+ important Abstraction in OOPs concepts  interview questions and answer in java for freshers and experienced candidates one by one topics.



            This post on JAVA Interview Questions and Answers is prepared to help you understand the basic concepts of Java programming for top composes interview purposes. All the most important JAVA concepts are explained here with examples for your easy understanding.

             This blog covers core JAVA topics, advance java topics and also industry level project related most important Interview Questions with examples to make you get ready perfectly to face any JAVA interview confidently.
Keywords Interview Questions and Answer --------- Static keyword and Final Keyword

Most Popular Java Interview Questions:

          Given below is a comprehensive list of most important and commonly asked about Abstraction in OOPs Concept basic and advanced Java programming interview questions with detailed answers.




1. What is Abstraction in Object Oriented programming?


             Abstraction is the process of hiding certain implementation details of an object and showing only essential features of the object to outside world. It is different from Abstract class in Java. Abstraction process identifies commonalities and hides the complexity of implementation. It helps us in focusing on the interface that we share with the outside world.

2. How is Abstraction different from Encapsulation?


            Abstraction happens at class level design. It results in hiding the implementation details. Encapsulation is also known as “Information Hiding”. An example of encapsulation is marking the member variables private and providing getter and setter for these member variables.

3. What is an abstract class in Java?


           An abstract class in Java has one or more abstract methods. An abstract method is just declared in the abstract class, but it is not implemented. An abstract class has to be extended in Java and its abstract methods have to be implemented by a child class. Also Java does not allow new instance of Abstract class.

4. Is it allowed to mark a method abstract method without marking the class abstract?


            No. Java specification says that if there is at least one abstract method in a class, the class has to be marked abstract.

5. Is it allowed to mark a method abstract as well as final?


            No. It will be contradictory statement to mark a method abstract as well as final. An abstract method has to be overridden by a child class. And a final method cannot be overridden. Therefore a method can be either abstract or final in Java.

6. Can we instantiate an abstract class in Java?


            No. We cannot create an instance of an abstract class in Java.

7.What is an interface in Java?


             An Interface in Java is an abstract type blueprint of a class. It contains the methods that a class must implement. It is like a protocol. It has method signatures and constant declarations.


8. Is it allowed to mark an interface method as static?


           Yes, from Java 8 onwards, we can define static and default methods in an interface. Prior to Java 8, it was not allowed.

9. Why an Interface cannot be marked as final in Java?


           A final method cannot be overridden. But an interface method has to be implemented by another class. So the interface method cannot be marked as final.

10. What is a marker interface?


           There are interfaces that do not have any data member or methods. These interfaces are called Marker interface.
E.g. Serializable, Cloneable, Remote etc.


11. What can we use instead of Marker interface?


            We can use annotations instead of Marker interface.

12. How Annotations are better than Marker Interfaces?


            Annotations serve the purpose of conveying metadata about the class to its consumers without creating a separate type for it. Annotations are more powerful than a Marker interface. They allow programmers to pass more sophisticated information to classes that "consume" it.

13. What is the difference between abstract class and interface in Java?


             Differences between Abstract class and Interface are as follows:
       1. An abstract class can have implemented methods with body (non-abstract methods). Interface has only abstract methods. From Java 8 onwards, interface can have static/default methods in implemented form.
       2. An abstract class can have instance member variables. An interface cannot have instance variables. It can only have constants.
       3. An abstract class can have a constructor. Interface cannot have constructor. It has to be implemented by another class.
       4. A class can extend only one abstract class. A class can implement more than one interface.


14. Does Java allow us to use private and protected modifiers for variables in interfaces?


             No. All the variables in an interface are implicitly public.

15. How can we cast to an object reference to an interface reference?


            An Object that implements an Interface can be cast to the same Interface. Since An Object implementing an Interface already provides implementation for the methods of that Interface, it is allowed to do so as per the rules of Inheritance.






Comments

Popular posts from this blog

DOCKER Interview questions

DOCKER 1. What is Docker? Docker is Open Source software. It provides the automation of Linux application deployment in a software container. We can do operating system level virtualization on Linux with Docker. Docker can package software in a complete file system that contains software code, runtime environment, system tools, & libraries that are required to install and run the software on a server. 2. What is the difference between Docker image and Docker container? Docker container is simply an instance of Docker image. A Docker image is an immutable file, which is a snapshot of container. We create an image with build command. When we use run command, an Image will produce a container. In programming language, an Image is a Class and a Container is an instance of the class. 3. How will you remove an image from Docker? We can use docker rmi command to delete an image from our local system. Exact command is: % docker rmi <Image Id> If we want to fin...

Cloud Computing Interview Questions

Cloud Computing 1. What are the benefits of Cloud Computing? There are ten main benefits of Cloud Computing: Flexibility : The businesses that have fluctuating bandwidth demands need the flexibility of Cloud Computing. If you need high bandwidth, you can scale up your cloud capacity. When you do not need high bandwidth, you can just scale down. There is no need to be tied into an inflexible fixed capacity infrastructure. Disaster Recovery : Cloud Computing provides robust backup and recovery solutions that are hosted in cloud. Due to this there is no need to spend extra resources on homegrown disaster recovery. It also saves time in setting up disaster recovery. Automatic Software Updates : Most of the Cloud providers give automatic software updates. This reduces the extra task of installing new software version and always catching up with the latest software installs. Low Capital Expenditure : In Cloud computing the model is Pay as you Go. This means there is very...

Microservices Interview Questions

Microservices Interview Questions 1. What is a Microservice in Java? A Microservice is a small and autonomous piece of code that does one thing very well. It is focused on doing well one specific task in a big system. It is also an autonomous entity that can be designed, developed and deployed independently. Generally, it is implemented as a REST service on HTTP protocol, with technology-agnostic APIs. Ideally, it does not share database with any other service. 2. What are the benefits of Microservices architecture? Microservices provide many benefits. Some of the key benefits are: 1.      Scaling : Since there are multiple Microservices instead of one monolith, it is easier to scale up the service that is being used more. Eg. Let say, you have a Product Lookup service and Product Buy service. The frequency of Product Lookup is much higher than Product Buy service. In this case, you can just scale up the Product Lookup service to run on powerful ha...