Contact Us
A 101-103 Siddhivinayak Towers, Off S.G. Highway, Ahmedabad, Gujarat 380051

Java Interview Questions Part I

by Attune World Wide / /

What is JAVA?

Java is the high-level, object-oriented, robust, secure programming language, platform-independent, high performance, Multithreaded, and portable programming language.

What are the features in JAVA?

  • Oops concepts: Object-oriented, Inheritance, Encapsulation, Polymorphism, Abstraction
  • Platform independent
  • High Performance
  • Multi-threaded

What are the various access modifiers in Java?

In Java, access specifiers are the keywords which are used to define the access scope of the method, class, or a variable. In Java, there are four access specifiers given below.

Public The classes, methods, or variables which are defined as public, can be accessed by any class or method.

  • Protected Protected c an be accessed by the class of the same package, or by the sub-class of this class, or within the same class.
  • Default Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.
  • Private The private class, methods, or variables defined as private can be accessed within the class only.

What is the purpose of static methods and variables?

  • The methods or variables defined as static are shared among all the objects of the class.
  • The static is the part of the class and not of the object.
  • The static variables are stored in the class area, and we do not need to create the object to access such variables.
  • Therefore, static is used in the case, where we need to define variables or methods which are common to all the objects of the class.

What is an object?

  • The Object is the real-time entity having some state and behavior.
  • In Java, Object is an instance of the class having the instance variables as the state of the object and the methods as the behavior of the object.
  • The object of a class can be created by using the new keyword.

What is oops Concept?

Abstraction : Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user.

Encapsulation : Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit.

Inheritance: Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another.The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class).

extends is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword.

Types of Inheritance

1) Single Inheritance 2) Multi level Inheritance 3) Hierarchical Inheritance 4) Multiple Inheritance

Polymorphism : Polymorphism in Java is a concept by which we can perform a single action in different ways. There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism.We can perform polymorphism in java by method overloading and method overriding.

What is Method Overloading and Overriding?

Method Overloading : If a class has multiple methods having same name but different in parameters, it is known as Method Overloading.

There are two ways to overload the method in java

  1. By changing number of arguments
  2. By changing the data type

Method Overriding : If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java.

What do you mean by Constructor?

  • When a new object is created in a program a constructor gets invoked corresponding to the class.
  • The constructor is a method which has the same name as class name.
  • If a user doesn’t create a constructor implicitly a default constructor will be created.
  • The constructor can be overloaded.
  • If the user created a constructor with a parameter then he should create another constructor explicitly without a parameter.

There are two types of constructors in Java.

  • Default Constructor: default constructor is the one which does not accept any value. The default constructor is mainly used to initialize the instance variable with the default values.
  • Parameterized Constructor: The parameterized constructor is the one which can initialize the instance variables with the given values.

What is Local Variable and Instance variable?

Local variable : They are defined in the method and scope of the variables that have existed inside the method itself.

Instance variable : It is defined inside the class and outside the method and scope of the variables exist throughout the class.

What is an 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.

About Attune World Wide

What you can read next

Leave a Reply

Your email address will not be published. Required fields are marked *

18 − four =

Recent Posts