• Slider Banner

    Prepare for

    Technical Interview

    Over .1 Million+ Interview Questions for different profiles

    Read More
  • Slider Banner

    Join the

    Programming World

    Learn about top programming languages, tools and frameworks.

    Read More
  • Slider Banner

    Prepare with

    Certification MCQ

    Practice for certification from 1000+ multiple choice questions.

    Read More

What is object cloning in Java?

Object cloning in Java is the process of creating an exact copy of an object. It basically means the ability to create an object with a similar state as the original object. To achieve this, Java provides a method clone() to make use of this functionality.

This method creates a new instance of the class of the current object and then initializes all its fields with the exact same contents of corresponding fields. To object clone(), the marker interface java.lang.Cloneable must be implemented to avoid any runtime exceptions. One thing you must note is Object clone() is a protected method, thus you need to override it.

What is composition in Java?

Composition is again a specialized form of Aggregation and we can call this as a "death" relationship. It is a strong type of Aggregation. Child object does not have their lifecycle and if parent object deletes all child object will also be deleted.

Let's take again an example of a relationship between House and rooms. House can contain multiple rooms there is no independent life of room and any room can not belongs to two different houses if we delete the house room will automatically delete.

What do you mean by aggregation in Java?

An aggregation is a specialized form of Association where all object has their own lifecycle but there is ownership and child object can not belong to another parent object. Let’s take an example of Department and teacher. A single teacher can not belong to multiple departments, but if we delete the department teacher object will not destroy. 

What is an association in Java?

Association is a relationship where all object have their own lifecycle and there is no owner. Let's take the example of Teacher and Student. Multiple students can associate with a single teacher and a single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle.

These relationships can be one to one, one to many, many to one and many to many.

What is multiple inheritance? Is it supported by Java?

If a child class inherits the property from multiple classes its known as multiple inheritance. For Example: Class C extends B, A. Java does not allow to extend multiple classes.

The problem with multiple inheritance is that if multiple parent classes have the same method name, then at runtime it becomes difficult for the compiler to decide which method to execute from the child class.

Therefore, Java doesn’t support multiple inheritance. The problem is commonly referred to as Diamond Problem.

Can you override a private or static method in Java?

You cannot override a private or static method in Java. If you create a similar method with the same return type and same method arguments in child class then it will hide the superclass method; this is known as method hiding.

Similarly, you cannot override a private method in subclass because it’s not accessible there. What you can do is create another private method with the same name in the child class. 

What are the different types of inheritance in Java?

Java supports four types of inheritance which are:

  1. Single Inheritance: In single inheritance, one class inherits the properties of another i.e there will be only one parent as well as one child class. For example Class B extends A.
  2. Multilevel Inheritance: When a class is derived from a class which is also derived from another class, i.e. a class  having more than one parent class but at different levels, such type of inheritance is called Multilevel Inheritance. For Example: Class B extends A and then Class C extends A.
  3. Hierarchical Inheritance: When a class has more than one child classes (subclasses) or in other words, more than one child classes have the same parent class, then such kind of inheritance is known as hierarchical. For Example: Class B extends A. Class C extends A.
  4. Hybrid Inheritance: Hybrid inheritance is a combination of two or more types of inheritance.

What will be the output of below Java code?

Example Code: 

public class A
{
    public static void main(String[] args)
    {
        String x = null;
        m2(x);
        
        System.out.println(x);
    }
    static void m2(String s)
    {
        s = "Vinay";
    }
}

Output: null

What are the strategies that can be used to grow business through Instagram?

1. Create an Instagram Account: This is the first step to start with creating Instagram account . Which helps in driving people to landing page so that you get email id or contact details and can reach to them.

2. Define Target Audience: To define the target audience is the most important step for any social platform. It will help to reach only the defined audience. So as to compel and happy to buy your product with in the defined periphery.


3. Photo Ads: Some other steps so as to make more engagement to the page and to drive the audience. Such as creating simple Photo ads as to promote through photo of your product.

4. Video Ads:  60 secs long video also can be created may  be in landscape or square mode. This is super powerful as user love videos to interact with.

5. Carousel Ads: This is kind of creating a bunch of photos in sequence. Like to show more than one product photos or if to show one product it can be shown with different features of that product.

6. Stories Ads:  Creating videos on instagram stories. Then people can follow your brand. Lot of users are going on instagram stories directly in spite going to timelines. We can connect with 250+ million people using stories daily

Subscribe to