Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Can There Be Any Abstract Method Without Abstract Class?

Answer»

No, if there is any ABSTRACT METHOD in a CLASS, that class MUST be abstract.

No, if there is any abstract method in a class, that class must be abstract.

2.

What Is Covariant Return Type?

Answer»

The covariant return TYPE specifies that the return type may vary in the same direction as the subclass.

Before Java5, it was not possible to override any method by changing the return type. But now, since Java5, it is possible to override method by changing the return type if subclass OVERRIDES any method WHOSE return type is Non-Primitive but it CHANGES its return type to subclass type.

The covariant return type specifies that the return type may vary in the same direction as the subclass.

Before Java5, it was not possible to override any method by changing the return type. But now, since Java5, it is possible to override method by changing the return type if subclass overrides any method whose return type is Non-Primitive but it changes its return type to subclass type.

3.

What Is Blank Or Uninitialized Final Variable?

Answer»

A FINAL variable that is not initialized at the time of DECLARATION is known as blank final variable.

If you want to create a variable that is initialized at the time of creating object and once initialized MAY not be CHANGED, it is useful. For example PAN CARD number of an employee. It can be initialized only in constructor.

A final variable that is not initialized at the time of declaration is known as blank final variable.

If you want to create a variable that is initialized at the time of creating object and once initialized may not be changed, it is useful. For example PAN CARD number of an employee. It can be initialized only in constructor.

4.

Can You Use Abstract And Final Both With A Method?

Answer»

No, because abstract method NEEDS to be OVERRIDDEN whereas you can't override FINAL method.

No, because abstract method needs to be overridden whereas you can't override final method.

5.

Difference Between Method Overloading And Overriding.

Answer»

Method OVERLOADING :

  • Method overloading increases the readability of the PROGRAM.
  • method overlaoding is OCCURS within the class.
  • In this case, parameter must be different.

Method Overriding :

  • Method overriding provides the SPECIFIC implementation of the method that is already provided by its super class.
  • Method overriding occurs in two classes that have IS-A RELATIONSHIP.
  • In this case, parameter must be same.

Method Overloading :

Method Overriding :

6.

Why We Cannot Override Static Method?

Answer»

It is because the STATIC method is the PART of class and it is bound with class whereas instance method is bound with object and static gets MEMORY in class area and instance gets memory in heap.

It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap.

7.

Can We Override Static Method?

Answer»

No, you can't OVERRIDE the static METHOD because they are the part of class not OBJECT.

No, you can't override the static method because they are the part of class not object.

8.

What Will Be The Initial Value Of An Object Reference Which Is Defined As An Instance Variable?

Answer»

The OBJECT REFERENCES are all INITIALIZED to NULL in JAVA.

The object references are all initialized to null in Java.

9.

What Is Difference Between Object Oriented Programming Language And Object Based Programming Language?

Answer»

Object BASED programming languages FOLLOW all the features of OOPS except Inheritance. Examples of object based programming languages are JavaScript, VBSCRIPT etc.

Object based programming languages follow all the features of OOPs except Inheritance. Examples of object based programming languages are JavaScript, VBScript etc.

10.

What Is The Difference Between Static Binding And Dynamic Binding?

Answer»

In CASE of STATIC binding type of OBJECT is determined at COMPILE time whereas in dynamic binding type of object is determined at runtime.

In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime.

11.

What Is Runtime Polymorphism?

Answer»
  • Runtime polymorphism or DYNAMIC method dispatch is a process in which a call to an overridden method is RESOLVED at runtime rather than at compile-time.
  • In this process, an overridden method is called through the reference variable of a SUPER class. The determination of the method to be called is based on the object being REFERRED to by the reference variable.

12.

Can You Access Non Static Variable In Static Context?

Answer»

A static variable in Java BELONGS to its class and its value remains the same for all its instances. A static variable is initialized when the class is loaded by the JVM. If your CODE TRIES to access a non-static variable, without any instance, the COMPILER will COMPLAIN, because those variables are not created yet and they are not associated with any instance.

A static variable in Java belongs to its class and its value remains the same for all its instances. A static variable is initialized when the class is loaded by the JVM. If your code tries to access a non-static variable, without any instance, the compiler will complain, because those variables are not created yet and they are not associated with any instance.

13.

What Does The “static” Keyword Mean ? Can You Override Private Or Static Method In Java ?

Answer»

The static keyword DENOTES that a member variable or method can be accessed, WITHOUT requiring an instantiation of the class to which it belongs. A user cannot override static methods in Java, because method overriding is based upon dynamic binding at runtime and static methods are STATICALLY BINDED at compile time. A static method is not associated with any instance of a class so the concept is not APPLICABLE.

The static keyword denotes that a member variable or method can be accessed, without requiring an instantiation of the class to which it belongs. A user cannot override static methods in Java, because method overriding is based upon dynamic binding at runtime and static methods are statically binded at compile time. A static method is not associated with any instance of a class so the concept is not applicable.

14.

What Are Pass By Reference And Pass By Value?

Answer»

When an OBJECT is passed by value, this means that a COPY of the object is passed. Thus, even if changes are made to that object, it doesn’t affect the original value. When an object is passed by reference, this means that the actual object is not passed, rather a reference of the object is passed. Thus, any changes made by the external method, are also REFLECTED in all PLACES.

When an object is passed by value, this means that a copy of the object is passed. Thus, even if changes are made to that object, it doesn’t affect the original value. When an object is passed by reference, this means that the actual object is not passed, rather a reference of the object is passed. Thus, any changes made by the external method, are also reflected in all places.

15.

What Is A Constructor, Constructor Overloading In Java And Copy-constructor?

Answer»

A constructor gets invoked when a new object is created. Every class has a constructor. In case the programmer does not provide a constructor for a class, the Java compiler (Javac) creates a default constructor for that class. The constructor OVERLOADING is similar to method overloading in Java. Different constructors can be created for a single class. Each constructor must have its own UNIQUE parameter list. Finally, Java does support COPY constructors like C++, but the difference lies in the fact that Java doesn’t create a default copy constructor if you don’t write your own.

 

A constructor gets invoked when a new object is created. Every class has a constructor. In case the programmer does not provide a constructor for a class, the Java compiler (Javac) creates a default constructor for that class. The constructor overloading is similar to method overloading in Java. Different constructors can be created for a single class. Each constructor must have its own unique parameter list. Finally, Java does support copy constructors like C++, but the difference lies in the fact that Java doesn’t create a default copy constructor if you don’t write your own.

 

16.

Whatt Is Function Overriding And Overloading In Java ?

Answer»

Method OVERLOADING in Java occurs when two or more methods in the same class have the EXACT same name, but different parameters. On the other hand, method OVERRIDING is defined as the case when a child class redefines the same method as a parent class. Overridden methods must have the same name, argument LIST, and return type. The overriding method may not limit the access of the method it OVERRIDES.

Method overloading in Java occurs when two or more methods in the same class have the exact same name, but different parameters. On the other hand, method overriding is defined as the case when a child class redefines the same method as a parent class. Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides.

17.

What Is The Differences Between Abstraction And Encapsulation?

Answer»

Abstraction and encapsulation are complementary concepts. On the one HAND, abstraction focuses on the behavior of an object. On the other hand, encapsulation focuses on the implementation of an object’s behavior. Encapsulation is usually ACHIEVED by hiding information about the INTERNAL state of an object and thus, can be seen as a STRATEGY used in ORDER to provide abstraction.

Abstraction and encapsulation are complementary concepts. On the one hand, abstraction focuses on the behavior of an object. On the other hand, encapsulation focuses on the implementation of an object’s behavior. Encapsulation is usually achieved by hiding information about the internal state of an object and thus, can be seen as a strategy used in order to provide abstraction.

18.

What Is Difference Between Polymorphism And Inheritance?

Answer»
  • Inheritance defines parent-child RELATIONSHIP between two classes, polymorphism take advantage of that relationship to add dynamic behaviour in your code.
  • Inheritance helps in code reusability by allowing child class to INHERIT behavior from the parent class. On the other hand Polymorphism allows Child to redefine already defined behaviour inside parent class. Without Polymorphism it's not possible for a Child to execute its own behaviour while REPRESENTED by a Parent reference variable, but with Polymorphism he can do that.
  • Java doesn't allow multiple inheritance of classes, but allows multiple inheritance of Interface, which is actually require to implement Polymorphism. For example a Class can be Runnable, Comparator and SERIALIZABLE at same time, because all three are interfaces. This makes them to pass around in code e.g. you can pass instance of this class to a METHOD which accepts Serializable, or to Collections.sort() which accepts a Comparator.
  • Both Polymorphism and Inheritance allow Object oriented programs to evolve. For example, by using Inheritance you can define new user types in an Authentication System and by using Polymorphism you can take advantage of already written authentication code. Since, Inheritance guarantees minimum base class behaviour, a method depending upon super class or super interface can still accept object of base class and can authenticate it.

19.

What Is Association?

Answer»

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 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.

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 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.

20.

What Is Multiple Inheritance And Does Java Support?

Answer»

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 with multiple inheritance is that if multiple parent classes has a same method name, the at runtime it becomes diffcult for compiler to decide which method to execute from the child class. To overcome this problem it allows to IMPLEMENT multiple Interfaces.

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 with multiple inheritance is that if multiple parent classes has a same method name, the at runtime it becomes diffcult for compiler to decide which method to execute from the child class. To overcome this problem it allows to implement multiple Interfaces.

21.

What Is Meant By Static Binding?

Answer»

Static BINDING is a binding in which the CLASS ASSOCIATION is MADE during compile time. This is ALSO called as early binding.

Static binding is a binding in which the class association is made during compile time. This is also called as early binding.

22.

What Is Meant By Abstraction?

Answer»

ABSTRACTION defines the essential characteristics of an object that distinguish it from all other kinds of OBJECTS. Abstraction provides crisply-defined conceptual boundaries RELATIVE to the PERSPECTIVE of the viewer. It’s the process of focusing on the essential characteristics of an object. Abstraction is ONE of the fundamental elements of the object model.

Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. It’s the process of focusing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

23.

What Is Meant By Polymorphism?

Answer»

POLYMORPHISM literally means taking more than one form. Polymorphism is a characteristic of being ABLE to assign a different BEHAVIOR or value in a subclass, to SOMETHING that was declared in a parent class.

Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class.

24.

What Is Meant By Persistence?

Answer»

PERSISTENCE is the property of an OBJECT by which its EXISTENCE transcends SPACE and time.

Persistence is the property of an object by which its existence transcends space and time.

25.

What Is Meant By Object Oriented Programming?

Answer»

OOP is a METHOD of PROGRAMMING in which programs are ORGANIZED as cooperative collections of objects. Each object is an INSTANCE of a CLASS and each class belong to a hierarchy.

OOP is a method of programming in which programs are organized as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

26.

What Is Meant By Inheritance?

Answer»

Inheritance is a relationship among classes, wherein one class SHARES the STRUCTURE or behavior defined in another class. This is CALLED Single Inheritance. If a class shares the structure or behavior from MULTIPLE classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalized superclasses.

Inheritance is a relationship among classes, wherein one class shares the structure or behavior defined in another class. This is called Single Inheritance. If a class shares the structure or behavior from multiple classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalized superclasses.

27.

What Is Meant By Encapsulation?

Answer»

Encapsulation is the PROCESS of compartmentalizing the elements of an abstraction that defines the structure and BEHAVIOR. Encapsulation HELPS to separate the contractual INTERFACE of an abstraction and IMPLEMENTATION.

Encapsulation is the process of compartmentalizing the elements of an abstraction that defines the structure and behavior. Encapsulation helps to separate the contractual interface of an abstraction and implementation.

28.

What Is Meant By Dynamic Binding?

Answer»

DYNAMIC BINDING is a binding in which the class association is not made until the object is created at EXECUTION TIME. It is also called as LATE binding.

Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as late binding.

29.

What Is Meant By Binding?

Answer»

BINDING DENOTES ASSOCIATION of a NAME with a CLASS

Binding denotes association of a name with a class

30.

What Is Collaboration?

Answer»

COLLABORATION is a process whereby several objects COOPERATE to provide some HIGHER level BEHAVIOR.

Collaboration is a process whereby several objects cooperate to provide some higher level behavior.

31.

What Is A Subclass?

Answer»

SUBCLASS is a CLASS that INHERITS from ONE or more CLASSES.

Subclass is a class that inherits from one or more classes.