Top thirty OOP Concept Interview Questions Answers inwards Java - Object Oriented Programming

Java is an object-oriented programming linguistic communication as well as y'all volition come across a lot of object oriented programming concept questions on Java interviews. The classic questions similar departure betwixt interface as well as abstract shape are ever in that place but from the lastly couplet of years to a greater extent than sophisticated questions based upon advanced pattern principles as well as patterns are too asked to cheque OOP noesis of the candidate. Though, Object oriented programming questions are to a greater extent than pop on Java interviews for 1 to iii years experienced programmers. It makes sense equally well, equally these are the programmers who must know the OOP basic similar Abstraction, Inheritance, Composition, Class, Object, Interface, Encapsulation etc.

If y'all await for Java interview questions for 2 to iv years experienced programmer, y'all volition detect lots of questions based upon OOP fundamentals similar Inheritance as well as Encapsulation but equally y'all gain to a greater extent than experience, y'all volition come across questions based on object-oriented analysis as well as pattern e.g. code a vending pattern machine or implement a coffeemaker inwards Java.

These questions are to a greater extent than hard as well as require non exclusively truthful agreement of OOP exchange but too nigh SOLID pattern principles as well as patterns.



OOPS Concept Interview Questions inwards Java

In this article, I am going to part y'all about OOPS concept based Java interview questions which I receive got collected from friends as well as colleagues as well as they receive got seen inwards diverse Java interviews on dissimilar companies. They are to a greater extent than frequently than non asked at kickoff few circular e.g. on screening circular or on the telephonic round.


If y'all are senior Java developer as well as so y'all already know answers to this inquiry as well as I advise y'all exercise to a greater extent than on object-oriented analysis as well as pattern science i.e. how to do code against a specification. If y'all are fresher as well as junior Java developer amongst 2 to iii years sense as well as so y'all must revise these questions, larn if y'all don't know to do good on your Java Job interviews.


What is method overloading inwards OOP or Java? (answer)
It's 1 of the oldest OOPS concept questions, I receive got seen it 10 years agone as well as nevertheless sees it now. When nosotros receive got multiple methods amongst the same advert but dissimilar functionality as well as so it's called method overloading. For example. System.out.println() is overloaded equally nosotros receive got vi or vii println() method each accepting a dissimilar type of parameter.


What is method overriding inwards OOP or Java? (answer)
It's 1 of the magic of object oriented programming where the method is chose based upon an object at runtime. In fellowship for method overriding, nosotros demand Inheritance as well as Polymorphism, equally nosotros demand a method amongst the same signature inwards both superclass as well as subclass. Influenza A virus subtype H5N1 telephone telephone to such method is resolved at runtime depending upon the actual object as well as non the type o variable. See the reply for to a greater extent than detailed discussion.


What is method hiding inwards Java? (answer)
When y'all declare 2 static methods amongst same advert as well as signature inwards both superclass as well as subclass as well as so they enshroud each other i.e. a telephone telephone to the method inwards the subclass volition telephone telephone the static method declared inwards that shape as well as a telephone telephone to the same method is superclass is resolved to the static method declared inwards the super class.


Is Java a pure object oriented language? if non why? (answer)
Java is non a pure object-oriented programming linguistic communication e.g. in that place are many things y'all tin do without objects e.g. static methods. Also, primitive variables are non objects inwards Java. See the reply for a to a greater extent than detailed explanation.



What are rules of method overloading as well as overriding inwards Java? (answer)
One of the most of import rules of method overloading inwards Java is that method signature should live dissimilar i.e. either the pose out of arguments or the type of arguments. Simply changing the render type of 2 methods volition non trial inwards overloading, instead, the compiler volition throw an error. On the other hand, method overriding has to a greater extent than rules e.g. advert as well as render type must live same, method signature should too live same, the overloaded method cannot throw a higher exception etc. See the reply for a sum listing of rules related to method overloading as well as overriding inwards Java.


The departure betwixt method overloading as well as overriding? (answer)
Several differences but the most of import 1 is that method overloading is resolved at compile fourth dimension as well as method overriding is resolved at runtime. The compiler exclusively used the shape information for method overloading, but it needs to know object to resolved overridden method calls. This diagram explains the departure quite well, though:

oriented programming linguistic communication as well as y'all volition come across a lot of object oriented programming concep Top xxx OOP Concept Interview Questions Answers inwards Java - Object Oriented Programming


Can nosotros overload a static method inwards Java? (answer)
Yes, y'all tin overload a static method inwards Java. You tin declare equally many static methods of the same advert equally y'all wishing provided all of them receive got dissimilar method signatures. See the reply for to a greater extent than detailed explanation as well as code example.


Can nosotros override static method inwards Java? (answer)
No, y'all cannot override a static method because it's non bounded to an object. Instead, static methods belong to a shape as well as resolved at compile fourth dimension using the type of reference variable. But, Yes, y'all tin declare the same static method inwards a subclass, that volition trial inwards method hiding i.e. if y'all usage reference variable of type subclass as well as so novel method volition live called, but if y'all usage reference variable of superclass than old method volition live called.


Can nosotros forbid overriding a method without using the terminal modifier? (answer)
Yes, y'all tin forbid the method overriding inwards Java without using the terminal modifier. In fact, in that place are several ways to reach it e.g. y'all tin grade the method private or static, those cannot live overridden.


Can nosotros override a private method inwards Java? (answer)
No, y'all cannot. Since the private method is exclusively accessible as well as visible within the shape they are declared, it's non possible to override them inwards subclasses. Though, y'all tin override them within the inner shape equally they are accessible there.


What is covariant method overriding inwards Java? (answer)
In covariant method overriding, the overriding method tin render the subclass of the object returned past times master or overridden method. This concept was introduced inwards Java 1.5 (Tiger) version as well as it's really helpful inwards instance master method is returning full general type similar Object class, because, as well as so past times using covariant method overriding y'all tin render to a greater extent than suitable object as well as forbid customer side type casting. One of the practical usage of this concept is inwards when y'all override the clone() method inwards Java.



Can nosotros alter the render type of method to subclass spell overriding? (answer)
Yes, y'all can, but exclusively from Java five onward. This characteristic is known equally covariant method overriding as well as it was introduced inwards JDK five release. This is immensely helpful if master method render super-class e.g. clone() method render java.lang.Object. By using this, y'all tin straight render the actual type, preventing client-side type casting of the result.


Can nosotros alter the declaration listing of an overriding method? (answer)
No, y'all cannot. The declaration listing is portion of the method signature as well as both overriding as well as overridden method must receive got the same signature.


Can nosotros override a method which throws runtime exception without throws clause? (answer)
Yes, in that place is no restriction on unchecked exception spell overriding. On the other hand, inwards the instance of checked exception, an overriding exception cannot throw a checked exception which comes higher inwards type hierarchy e.g. if master method is throwing IOException than overriding method cannot throw java.lang.Exception or java.lang.Throwable.


How do y'all telephone telephone superclass version of an overriding method inwards sub class? (answer)
You tin telephone telephone a superclass version of an overriding method inwards the subclass past times using super keyword. For illustration to telephone telephone the toString() method from java.lang.Object shape y'all tin telephone telephone super.toString().


Can nosotros override a non-static method equally static inwards Java? (answer)
Yes, y'all tin override the non-static method inwards Java, no work on them but it should non live private or terminal :)


Can nosotros override the terminal method inwards Java? (answer)
No, y'all cannot override a terminal method inwards Java, terminal keyword amongst the method is to forbid method overriding. You usage terminal when y'all don't desire subclass changing the logic of your method past times overriding it due to safety reason. This is why String shape is terminal inwards Java. This concept is too used inwards template pattern pattern where template method is made terminal to forbid overriding.



Can nosotros receive got a non-abstract method within interface? (answer)
From Java 8 onward y'all tin receive got a non-abstract method within interface, prior to that it was non allowed equally all method was implicitly populace abstract. From JDK 8, y'all tin add together static as well as default method within an interface.


What is the default method of Java 8? (answer)
Default method, too known equally extension method are novel types of the method which y'all tin add together on the interface now. These method has implementation as well as intended to live used past times default. By using this method, JDK 8 managed to render mutual functionality related to lambda expression as well as stream API without breaking all the clients which implement their interfaces. If y'all await Java 8 API documentation y'all volition detect several useful default method on key Java interface similar Iterator, Map etc.


What is an abstract shape inwards Java? (answer)
An abstract shape is a shape which is incomplete. You cannot create an instance of an abstract shape inwards Java. They are provided to define default demeanor as well as ensured that customer of that shape should adore to those contract which is defined within the abstract class. In fellowship to usage it, y'all must extend as well as implement their abstract methods. BTW, inwards Java, a shape tin live abstract without specifying whatever abstract method.


What is an interface inwards Java? What is the existent user of an interface? (answer)
Like an abstract class, the interface is too in that place to specify the contract of an API. It supports OOP abstraction concept equally it defines exclusively abstract behavior. It volition tell that your computer program volition give output but how is left to implementors. The existent usage of the interface to define types to leverage Polymorphism. See the reply for to a greater extent than detailed explanation as well as discussion.


The departure betwixt Abstract shape as well as interface? (answer)
In Java, the key departure is that abstract shape tin comprise non-abstract method but the interface cannot, but from Java 8 onward interface tin too comprise static as well as default methods which are non-abstract. See the reply for to a greater extent than detailed intelligence equally I receive got described a lot of points there.

oriented programming linguistic communication as well as y'all volition come across a lot of object oriented programming concep Top xxx OOP Concept Interview Questions Answers inwards Java - Object Oriented Programming


Can nosotros brand a shape abstract without an abstract method? (answer)
Yes, but add together abstract keyword on the shape Definition as well as your shape volition acquire abstract.


Can nosotros brand a shape both terminal as well as abstract at the same time? (answer)
No, y'all cannot apply both terminal as well as abstract keyword at the shape same fourth dimension because they are precisely reverse of each other. Influenza A virus subtype H5N1 terminal shape inwards Java cannot live extended as well as y'all cannot usage an abstract shape without extending as well as snuff it far a concrete class. As per Java specification, the compiler volition throw an mistake if y'all endeavour to brand a shape abstract as well as terminal at the same time.


Can nosotros overload or override the principal method inwards Java? (answer)
No, since main() is a static method, y'all tin exclusively overload it, y'all cannot override it because the static method is resolved at compile fourth dimension without needing object information thence nosotros cannot override the principal method inwards Java.



What is the departure betwixt Polymorphism, Overloading, as well as Overriding? (answer)
This is slight tricky OOP concept inquiry because Polymorphism is the existent concept behind on both Overloading as well as Overriding. Overloading is compiled fourth dimension Polymorphism as well as Overriding are Runtime Polymorphism.


Can an interface extend to a greater extent than than 1 interface inwards Java?
Yes, an interface tin extend to a greater extent than than 1 interface inwards Java, it's perfectly valid.


Can a shape extend to a greater extent than than 1 shape inwards Java?
No, a shape tin exclusively extend about other shape because Java doesn't back upward multiple inheritances but yes, it tin implement multiple interfaces.


What is the departure betwixt abstraction as well as polymorphism inwards Java? (answer)
Abstraction generalizes the concept as well as Polymorphism allow y'all to usage dissimilar implementation without changing your code. This diagram explains the abstraction quite well, though:

oriented programming linguistic communication as well as y'all volition come across a lot of object oriented programming concep Top xxx OOP Concept Interview Questions Answers inwards Java - Object Oriented Programming


Object Oriented pattern regulation as well as pattern Interview Questions

Now let's come across about OOPS concept questions based on the SOLID pattern principles as well as GOF pattern patterns which convey payoff of OOPS concept discussed here.

What work is solved past times Strategy pattern inwards Java? (answer)
Strategy pattern allows y'all to innovate novel algorithm or novel strategy without changing the code which uses that algorithm. For example, the Collections.sort() method which sorts the listing of the object uses the Strategy pattern to compare object. Since every object uses dissimilar comparing strategy y'all tin compare diverse object differently without changing kind method.


Which OOP concept Decorator pattern Pattern is based upon? (answer)
Decorator pattern takes payoff of Composition to render novel features without modifying the master class. Influenza A virus subtype H5N1 really skillful to-the-point inquiry for the telephonic round. This is quite clear from UML diagram of Decorator pattern, equally y'all tin come across the Component is associated amongst Decorator.



When to usage Singleton pattern pattern inwards Java? (answer)
When y'all demand but 1 instance of a shape as well as wants that to live globally available as well as so y'all tin usage Singleton pattern. It's non gratuitous of damage though because it increases coupling betwixt classes as well as makes them hard to test. This is 1 of the oldest pattern pattern questions from Java interviews. Please come across the reply for to a greater extent than detailed discussion.


What is the departure betwixt State as well as Strategy Pattern? (answer)
Though the construction or shape diagram of State as well as Strategy pattern is same, their intent is completely different. State pattern is used to do something specific depending upon soil spell Strategy allows y'all to switch betwixt algorithms without changing the code which uses it.


What is the departure betwixt Association, Aggregation, as well as Composition inwards OOP? (answer)
When an object is related to about other object it called association. It has 2 forms, aggregation, as well as composition. the sometime is the loose shape of association where the related object tin travel individually spell afterward is a stronger shape of association where a related object cannot travel individually. For example, the urban centre is an aggregation of people but is the composition of trunk parts.



What is the departure betwixt Decorator, Proxy as well as Adapter pattern inwards Java? (answer)
Again they await similar because their construction or shape diagram is really similar but their intent is quite different. Decorator adds additional functionality without touching the class, Proxy provides access command as well as Adapter is used to brand 2 incompatible interfaces piece of work together. 


What is the five objects oriented pattern regulation from SOLID? (answer)
SOLID is the term given past times Uncle Bob inwards his classic book, the Clean Code, 1 of the must-read books for programmers. In SOLID each grapheme stands for 1 pattern principle:
due south for Single Responsibility Principle
O for Open unopen pattern principle
L for Liskov exchange principle
I for Interface segregation principle
D for Dependency inversion principle

oriented programming linguistic communication as well as y'all volition come across a lot of object oriented programming concep Top xxx OOP Concept Interview Questions Answers inwards Java - Object Oriented Programming


What is the departure betwixt Composition as well as Inheritance in OOP? (answer)
This is about other swell OOPS concept inquiry because it tests what matters, both of them are really of import from a shape pattern perspective. Though both Composition as well as Inheritance allows y'all to reuse code, formerly is to a greater extent than flexible than later. Composition allows the shape to acquire an additional characteristic at runtime, but Inheritance is static. You tin non alter the characteristic at runtime past times exchange novel implementation. See the reply for to a greater extent than detailed discussion.


That's all nigh inwards this listing of object oriented programming or OOPS concept interview questions. We receive got seen questions from diverse OOPS concept e.g. Abstraction, Encapsulation, Inheritance, Composition, Aggregation, Association, Class, Object as well as Interface etc.

We receive got too seen questions from Object oriented pattern principles too known equally SOLID principles as well as GOF pattern patterns similar Strategy, State, as well as Factory, which are based upon both object oriented programming concept as well as OOP pattern principle. But, equally I said, if y'all are senior Java developer as well as so y'all focus to a greater extent than on object-oriented analysis as well as pattern as well as larn how to code against a requirement using all your OOP knowledge. You tin too read Cracking the Coding Interview, sixth Edition to for to a greater extent than Object Oriented Programming questions.

Subscribe to receive free email updates:

0 Response to "Top thirty OOP Concept Interview Questions Answers inwards Java - Object Oriented Programming"

Posting Komentar