0% found this document useful (0 votes)
92 views

Webperco Soft Solutions - Interview Questions of Java

The document contains 12 interview questions related to Java programming. The questions cover topics like object state and behavior, method overriding and overloading, manipulators, constructors, ternary operators, exception handling, destructors, inline functions, access modifiers, and code examples to find duplicate elements in an array and the largest number in an array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Webperco Soft Solutions - Interview Questions of Java

The document contains 12 interview questions related to Java programming. The questions cover topics like object state and behavior, method overriding and overloading, manipulators, constructors, ternary operators, exception handling, destructors, inline functions, access modifiers, and code examples to find duplicate elements in an array and the largest number in an array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

WEBPERCO SOFT SOLUTIONS – INTERVIEW QUESTIONS OF JAVA

1. What do you understand by the terms state and behavior of an Object?

State (instance variables): Values assigned to the instance variables of an object make up the object's state.

Behavior (functions/methods): Methods/functions are where the class logic is stored. This is where the data gets
manipulated or algorithms get executed. Functions are also called procedures or methods. 

Variables are also called members, fields or attributes.

2. Method Overriding in java?

In Method Overriding a subclass/child class has the same method name, same method signature and same return
types (covariant return types) as a method in its parent class, then the child class method has overridden the
parent class method.
You can find the complete detail about Method Overriding here.

3.  Method Overloading in java?

A class with multiple methods by the same name but different parameters called Method Overloading.
You can find it in detail here.

4.  What are manipulators?

Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>)
operators on an object. Examples are end l and sets.

5. Explain the term constructor?

A constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation.
Rules for constructor are:

Constructor Name should be the same as a class name.

A constructor must have no return type.

6.  What is a ternary operator?

The ternary operator is said to be an operator which takes three arguments. Arguments and results are of different
data types, and it depends on the function. The ternary operator is also called a conditional operator.
7. Exception handling?

An exception is an event that occurs during the execution of a program. Exceptions can be of any type – Runtime
exception, Error exceptions. Those exceptions are adequately handled through exception handling mechanism like
try, catch, and throw keywords.

8. Destructor?

A destructor is a method which is automatically called when the object is made of scope or destroyed. Destructor
name is also same as class name but with the tilde symbol before the name.

9. What is an Inline function?

An inline function is a technique used by the compilers and instructs to insert complete body of the function
wherever that function is used in the program source code .

10.  What are the access modifiers?

Access modifiers determine the scope of the method or variables that can be accessed from other various objects
or classes. There are five types of access modifiers, and they are as follows:

Private

Protected

Public

Friend

Protected Friend

11. Program to print the duplicate elements of an array?

public class DuplicateElement {  

Public static void main(String[] args) {  

        //Initialize array  

        int [] arr = new int [] {1, 2, 3, 4, 2, 7, 8, 8, 3};  

        System.out.println("Duplicate elements in given array: ");  

        //Searches for duplicate element  

        for(int i = 0; i < arr.length; i++) {  

            for(int j = i + 1; j < arr.length; j++) {  

                if(arr[i] == arr[j])  
                    System.out.println(arr[j]);  

            }   }   }   }  

  

12. find Largest Number in an Array?

public class LargestInArrayExample{  

public static int getLargest(int[] a, int total){  

int temp;  

for (int i = 0; i < total; i++)   

        {  

            for (int j = i + 1; j < total; j++)   

            {  

                if (a[i] > a[j])   

                {  

                    temp = a[i];  

                    a[i] = a[j];  

                    a[j] = temp;  

                }  

            }  

        }  

       return a[total-1];  

}  

public static void main(String args[]){  

int a[]={1,2,5,6,3,2};  

int b[]={44,66,99,77,33,22,55};  

System.out.println("Largest: "+getLargest(a,6));  

System.out.println("Largest: "+getLargest(b,7));  }} 
OUTPUT:

Largest : 6

largest : 99

You might also like