My Interview Questions About java

What is java?:-

Java is a widely used object-oriented programming language and software platform that runs on billions of devices, including notebook computers, mobile devices, gaming consoles, medical devices and many others. The rules and syntax of Java are based on the C and C++ languages.When the language was invented in 1991 by James Gosling of Sun Microsystems (later acquired by Oracle), the primary goal was to be able to “write once, run anywhere.”

Method Overloading:-

Develop the method with same method name and different argument list is called method overloading

To achieve this inheritance this inheritance is not mandatory

while doing this we shouldn’t change method signature.

It is used to compile time polymorphism..

Method overriding:-

Inheriting the method and changing its implementation in the sub class according to the sub class specification is known as method overriding.

To achieve this inheritance is mandatory.

While doing we can change method signature.

It is used to achieve run time polymorphism

What is polymorphism:-

Image result for what is polymorphism

In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. A real-life example of polymorphism, a person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee.

Abstraction:-

Image result for what is abstraction in java?

In simple terms, abstraction “displays” only the relevant attributes of objects and “hides” the unnecessary details. For example, when we are driving a car, we are only concerned about driving the car like start/stop the car, accelerate/ break, etc.

What is interface?

An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types.

Difference between Abstract class and Interface:-

Abstract Class vs Interface

Abstract class vs Interface 

  • Type of methods: Interface can have only abstract methods. An abstract class can have abstract and non-abstract methods. From Java 8, it can have default and static methods also.
  • Final Variables: Variables declared in a Java interface are by default final. An abstract class may contain non-final variables.
  • Type of variables: Abstract class can have final, non-final, static and non-static variables. The interface has only static and final variables.
  • Implementation: Abstract class can provide the implementation of the interface. Interface can’t provide the implementation of an abstract class.
  • Inheritance vs Abstraction: A Java interface can be implemented using the keyword “implements” and an abstract class can be extended using the keyword “extends”.
  • Multiple implementations: An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
  • Accessibility of Data Members: Members of a Java interface are public by default. A Java abstract class can have class members like private, protected, etc.

Leave a Reply

Create your own website, free on WordPress.com.Create your own website.
Start free