Cognizant Technology Solutions Pvt Ltd FOR 2017 BATCH INTERVIEW

Cognizant Technology Solutions Pvt Ltd FOR 2017 BATCH

PROGRAM ANAYLST

DRIVE DATE 20/5/2018
cts Bengaluru
Address: Manayata Tech Park, Nagavara, Bengaluru, Karnataka 560045

Cognizant Technology Solutions Pvt Ltd FOR 2017 BATCH

PROGRAM ANAYLST

for chennai location

DRIVE DATE 19/5/2018
Address: 2nd Cross Street, Madras Export Processing Zone, Tambaram, Chennai, Tamil Nadu 600044

Cognizant Technology Solutions Pvt Ltd FOR 2017 BATCH

PROGRAM ANAYLST

for Hyderabad location

DRIVE DATE 19/5/2018

Address: 9-5-81, Ibrahim Bagh Road, Ibrahim Bagh, Hyderabad, Telangana 500031

Cognizant Technology Solutions Pvt Ltd  QUESTION  BY  JOBHUNTER TEAM

 

*********************************************************************************************

JUST FOCUS  ON RESUME  MENTOINED  SKILL  AS LIKE C, OR JAVA

************************************************************************************

 

Selection Process:

The company conducts recruitment process every year to select new candidates. The selection process of the company consists of 3 rounds. These rounds are as follows:

PPT Test

Aptitude Test

HR + Technical Interview

Academic Criteria:

A total of 60 percent throughout (Class X, XII and B.tech).

No backlogs.

Education gap of upto 1 year.

***********************************************************

INTERVIEW  EXPERINCE  DIFFERENT GUYS

**********************************************************

PAPER :  CTS PLACEMENT INTERVIEW PATTERN (HR And TECH)

 

Verbal and Non-verbal was very easy. Only problem is the time constraint, so a little bit of practicing before exams help.

 

After that it was HR+Tech ..

 

Me  – Good afternoon sir,

Hr –  good afternoon, please sit.

Me – Thank you, sir.

 

Hr  – so Chiranjib, tell me why do you want to join cognizant?

Me  – high growth rate, work environment .. bla bla bla ..

 

Hr  – so your hobbey is listening to music, what kind of music do you listen to ?

(I gave Music, Movies, Football, Computer Games, blogging and image editing/wallpaper designing as my hobby, so what ever you give as hobby, get a decent knowledge about that subject.)

Me  – mostly Rock and Metal. I am a big Pink Floyd fan.

 

Hr – what other bands you listen to other than pink Floyd ??

Me – sir,I also like bob Dylan and The Beatles .Nowadays I am also into death metal, I love Obituary etc .

 

Hr  – ok, what is you favorite Pink Floyd song?

Me  – (after a few second of pause as if I am trying to find which is my favorite pink Floyd song among hundreds of songs by them 😛 )Comfortably Numb.

 

Hr – hmmm, so you watch movies too, what kind of movies ??

Me – mainly European movies, I don’t like masala bolywood movies. movies like city of God, y tu mama tambien etc ..

 

Hr  – you have seen city of God (very impressed, at that time I was almost sure that I have done it ;)) .

 

Me – yes sir. infact I have seen CDD 3 times .. it’s a revolutionary movie.

 

After this it was more of a discussion on European and Mexican and Brazilian movies. I am a movie geek so no problem for me .. Again as I said get some good knowledge about your hobbies.

 

Hr – do you play football ?

Me – yes sir, I play for my class football team in college, though due to projects and lab woks don’t get time to practice too often .

 

Hr  – favorite team, favorite footballer ?

Me – Arsenal, henry and fabregas.

 

(I gave over-enthusiasm as my -ve point)

 

Hr  – why do you think over enthusiasm is a -ve aspect for you??

Me – said from a personal experience, how I once suffered for too much enthusiasm.

 

Hr  – ok , so do you have any problem with relocation ??

Me  – no sir .. and show some reasons why it wont be any problem.

 

Hr  – ok, do you have any question?

 

Me -(sadly I forgot to prepare for any question to ask 😛 ) after a bit stammering (acted as if I have too many question to ask 😛 ) what re we taught during that 2 months of training.

 

Hr  – answered.(please pay attention to what ever he/she says, and ask 1 or 2 question according to his answer to the first question, this will impress him/her very much as if you really want to join cognizant at any cost.)

 

Atyer 2-3 questions..

Hr – ok thank you.

Me -thank you sir.

 

So this is it. The interview barely lasted for 10 mintues. not a single tech question was asked to me. but some of my friend were interviewed for 30-40 mintues and those were completely tech interview question.

 

 

***********************************************

TECHNICAL ROUND:

 

Me: Good morning sir!

Sir: Good morning, take your seat.

Me: Thank you sir.

 

Sir: Well Vamsi, have you been to any other interviews before?

Me: Yes, sir.

 

Sir: Tell me about yourself.

Me: I told.

 

Sir: What is GPRS and explain?

Me: I explained.

 

Sir: What is CDMA and GSM and difference between them?

Me: The only I was expecting so explained in very well.

 

Sir: What are different types of antennas and their applications?

Me: I told him 15  different antennas by looking at my confidence he stopped me before saying applications.

 

Sir: Good Vamsi, do you know spectrum?

Me: I told in a something since I really don’t know anything.

 

Sir: Do you have an interest in Microprocessor?

Me: Yes sir, you can ask me any question, sir.

 

Sir: Ok. Not necessary, you are very confident.

 

Sir: Can you design me a NEW TRAFFIC CONTROLLER using DENSITY function?

Me: I thought ok it’s gone here I can packup. But I didn’t give up and took a paper and drew something like traffic junction and I didn’t keep silent just said some nonsense (Remember he just observes your confidence and your activeness and way you respond to question).

 

Sir: Ok good. What is 1996 x 1996?

Me: (2000-4)^2

 

Sir: Which day is Feb 10th 2010?

Me: Told.

 

Sir: Ok, I am done with my interview, do you have any questions for me?

Me: Sir! “how is my communications should I improve?

 

Sir: It’s good Vamsi, don’t slow, improve little bit.

Me: Sure and thank you sir, have a nice day.

 

HR ROUND:

 

Then I am called for HR.

 

But I didn’t prepare for HR.

 

I asked them 5 min permission and went to know something about Cognizant. But in mean time HR went through my resume :((

 

Me: May I come in mam?

HR: Yes, come in Vamsi, take your seat.

ME: Good evening mam and thank you.

 

HR: Vamsi, tell me about yourself in brief?

ME: Told very fast.

 

HR: Can you relocate?

ME: Yes, mam.

 

HR: Why did you change your college?

ME: Mam due to personal problems. (I change my college from BITS to KLU in my 4th sem)

 

HR: Ok, now you are ok here?

ME: Yes, mam.

 

HR: Ok, do you have any questions?

ME: The same I asked in TR rate my communication?

 

HR: You have to improve a lot Vamsi, but it’s fine you have 6 months time before joining the organization you can practice normal people can’t  catch your speed, she smiled : 🙂

ME: Sure mam, thank you, have a nice day, hope I see you again.

*************************************************************************************************************

 

 

 

*******************************************************

C Interview Questions and Answers

 

************************************************************

 

1)  How do you construct an increment statement or decrement statement in C?

 

Answer:There are actually two ways you can do this. One is to use the increment operator ++ and decrement operator –. For example, the statement “x++” means to increment the value of x by 1. Likewise, the statement “x –” means to decrement the value of x by 1. Another way of writing increment statements is to use the conventional + plus sign or – minus sign. In the case of “x++”, another way to write it is “x = x +1?.

 

 

 

2) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

 

Answer:Placing comment symbols /* */ around a code, also referred to as “commenting out”, is a way of isolating some codes that you think maybe causing errors in the program, without deleting the code. The idea is that if the code is in fact correct, you simply remove the comment symbols and continue on. It also saves you time and effort on having to retype the codes if you have deleted it in the first place.

 

 

 

3) What is the equivalent code of the following statement in WHILE LOOP format?

[c]

for (a=1; a<=100; a++)

printf (“%d\n”, a * a);

[/c]

 

Answer:[c]

a=1;

while (a<=100) {

printf (“%d\n”, a * a);

a++;

}

[/c]

 

 

 

4) What is spaghetti programming?

 

Answer:Spaghetti programming refers to codes that tend to get tangled and overlapped throughout the program. This unstructured approach to coding is usually attributed to lack of experience on the part of the programmer. Spaghetti programing makes a program complex and analyzing the codes difficult, and so must be avoided as much as possible.

 

 

 

5) In C programming, how do you insert quote characters (‘ and “) into the output screen?

 

Answer:This is a common problem for beginners because quotes are normally part of a printf statement. To insert the quote character as part of the output, use the format specifiers \’ (for single quote), and \” (for double quote).

 

 

 

6) What is the use of a ‘\0′ character?

 

Answer:It is referred to as a terminating null character, and is used primarily to show the end of a string value.

 

 

 

7) What is the difference between the = symbol and == symbol?

 

Answer:The = symbol is often used in mathematical operations. It is used to assign a value to a given variable. On the other hand, the == symbol, also known as “equal to” or “equivalent to”, is a relational operator that is used to compare two values.

 

 

 

8) Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

 

Answer:<> is incorrect. While this operator is correctly interpreted as “not  equal to” in writing conditional statements, it is not the proper operator to be used in C programming. Instead, the operator  !=  must be used to indicate “not equal to” condition.

 

 

 

9) Can the curly brackets { } be used to enclose a single line of code?

 

Answer:While curly brackets are mainly used to group several lines of codes, it will still work without error if you used it for a single line. Some programmers prefer this method as a way of organizing codes to make it look clearer, especially in conditional statements.

 

 

 

10) What are header files and what are its uses in C programming?

 

Answer:Header files are also known as library files. They contain two essential things: the definitions and prototypes of functions being used in a program. Simply put, commands that you use in C programming are actually functions that are defined from within each header files. Each header file contains a set of functions. For example: stdio.h is a header file that contains definition and prototypes of commands like printf and scanf.

 

 

 

11) Can I use  “int” data type to store the value 32768? Why?

 

Answer:No. “int” data type is capable of storing values from -32768 to 32767. To store 32768, you can use “long int” instead. You can also use “unsigned int”, assuming you don’t intend to store negative values.

 

 

 

12) Can two or more operators such as \n and \t be combined in a single line of program code

 

Answer:Yes, it’s perfectly valid to combine operators, especially if the need arises. For example: you can have a code like ” printf (“Hello\n\n\’World\’”) ” to output the text “Hello” on the first line and “World” enclosed in single quotes to appear on the next two lines.

 

 

 

13) Why is it that not all header files are declared in every C program?

 

Answer:The choice of declaring a header file at the top of each C program would depend on what commands/functions you will be using in that program. Since each header file contains different function definitions and prototype, you would be using only those header files that would contain the functions you will need. Declaring all header files in every program would only increase the overall file size and load of the program, and is not considered a good programming style.

 

 

 

14) When is the “void” keyword used in a function?

 

Answer:When declaring functions, you will decide whether that function would be returning a value or not. If that function will not return a value, such as when the purpose of a function is to display some outputs on the screen, then “void” is to be placed at the leftmost part of the function header. When a return value is expected after the function execution, the data type of the return value is placed instead of “void”.

 

 

 

15) What are compound statements?

 

Answer:Compound statements are made up of two or more program statements that are executed together. This usually occurs while handling conditions wherein a series of statements are executed when a TRUE or FALSE is evaluated. Compound statements can also be executed within a loop. Curly brackets { } are placed before and after compound statements.

 

 

 

16) Write a loop statement that will show the following output:

1

12

123

1234

12345

Answer:[c]

for (a=1; a<=5; i++) {

for (b=1; b<=a; b++)

printf(“%d”,b);

printf(“\n”);

}

[/c]

 

 

 

17) What is wrong in this statement?  scanf(“%d”,whatnumber);

 

Answer:An ampersand & symbol must be placed before the variable name whatnumber. Placing & means whatever integer value is entered by the user is stored at the “address” of the variable name. This is a common mistake for programmers, often leading to logical errors.

 

 

 

18) How do you generate random numbers in C?

 

Answer:Random numbers are generated in C using the rand() command. For example: anyNum = rand() will generate any integer number beginning from 0, assuming that anyNum is a variable of type integer.

 

 

 

19) What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

The most probable reason behind this error is that the header file for that function was not indicated at the top of the program. Header files contain the definition and prototype for functions and commands used in a C program. In the case of “tolower()”, the code “#include ” must be present at the beginning of the program.

 

 

 

20) What does the format %10.2 mean when included in a printf statement?

 

Answer:This format is used for two things: to set the number of spaces allotted for the output number and to set the number of decimal places. The number before the decimal point is for the allotted space, in this case it would allot 10 spaces for the output number. If the number of space occupied by the output number is less than 10, addition space characters will be inserted before the actual output number. The number after the decimal point sets the number of decimal places, in this case, it’s 2 decimal spaces.

 

 

 

21) What is wrong with this statement? myName = “Robin”;

 

Answer:You cannot use the = sign to assign values to a string variable. Instead, use the strcpy function. The correct statement would be: strcpy(myName, “Robin”);

 

 

22) How do you determine the length of a string value that was stored in a variable?

 

Answer:To get the length of a string value, use the function strlen(). For example, if you have a variable named FullName, you can get the length of the stored string value by using this statement: I = strlen(FullName); the variable I will now have the character length of the string value.

 

 

 

23) Is it possible to initialize a variable at the time it was declared?

 

Answer:Yes, you don’t have to write a separate assignment statement after the variable declaration, unless you plan to change it later on.  For example: char planet[15] = “Earth”; does two things: it declares a string variable named planet, then initializes it with the value “Earth”.

 

 

 

24) What are the different file extensions involved when programming in C?

 

Answer:Source codes in C are saved with .C file extension. Header files or library files have the .H file extension. Every time a program source code is successfully compiled, it creates an .OBJ object file, and an executable .EXE file.

 

 

 

25) What are reserved words?

 

Answer:Reserved words are words that are part of the standard C language library. This means that reserved words have special meaning and therefore cannot be used for purposes other than what it is originally intended for. Examples of reserved words are int, void, and return.

 

 

 

26) What are linked list?

 

Answer:A linked list is composed of nodes that are connected with another. In C programming, linked lists are created using pointers. Using linked lists is one efficient way of utilizing memory for storage.

 

 

 

27) What are binary trees?

 

Answer:Binary trees are actually an extension of the concept of linked lists. A binary tree has two pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node having two pointers as well.

 

 

 

28) Not all reserved words are written in lowercase. TRUE or FALSE?

 

Answer:FALSE. All reserved words must be written in lowercase; otherwise the C compiler would interpret this as unidentified and invalid.

 

 

 

29) What is wrong with this program statement? void = 10;

 

Answer:The word void is a reserved word in C language. You cannot use reserved words as a user-defined variable.

 

 

 

30) Is this program statement valid? INT = 10.50;

 

Answer:Assuming that INT is a variable of type float, this statement is valid. One may think that INT is a reserved word and must not be used for other purposes. However, recall that reserved words are express in lowercase, so the C compiler will not interpret this as a reserved word.

 

 

 

31) What is a newline escape sequence?

 

Answer:A newline escape sequence is represented by the \n character. This is used to insert a new line when displaying data in the output screen. More spaces can be added by inserting more \n characters. For example, \n\n would insert two spaces. A newline escape sequence can be placed before the actual output expression or after.

 

 

 

32) What is output redirection?

 

Answer:It is the process of transferring data to an alternative output source other than the display screen. Output redirection allows a program to have its output saved to a file. For example, if you have a program named COMPUTE, typing this on the command line as COMPUTE >DATA can accept input from the user, perform certain computations, then have the output redirected to a file named DATA, instead of showing it on the screen.

 

 

 

33) What is the difference between functions abs() and fabs()?

 

Answer:These 2 functions basically perform the same action, which is to get the absolute value of the given value. Abs() is used for integer values, while fabs() is used for floating type numbers. Also, the prototype for abs() is under , while fabs() is under .

 

 

 

34) Write a simple code fragment that will check if a number is positive or negative.

 

Answer:[c]

 

If (num>=0)

printf(“number is positive”);

else

printf (“number is negative”);

[/c]

 

 

 

35) What does the function toupper() do?

 

Answer:It is used to convert any letter to its upper case mode. Toupper() function prototype is declared in . Note that this function will only convert a single character, and not an entire string.

 

 

 

36) Which function in C can be used to append a string to another string?

 

Answer:The strcat function. It takes two parameters, the source string and the string value to be appended to the source string.

 

37) Dothese two program statements perform the same output? 1) scanf(“%c”, &letter);  2) letter=getchar()

 

Answer:Yes, they both do the exact same thing, which is to accept the next key pressed by the user and assign it to variable named letter.

 

 

 

38) What is the difference between text files and binary files?

 

Answer:Text files contain data that can easily be understood by humans. It includes letters, numbers and other characters. On the other hand, binary files contain 1s and 0s that only computers can interpret.

 

 

 

39) is it possible to create your own header files?

 

Answer:Yes, it is possible to create a customized header file. Just include in it the function prototypes that you want to use in your program, and use the #include directive followed by the name of your header file.

 

 

 

40) What is dynamic data structure?

 

Answer:Dynamic data structure provides a means for storing data more efficiently into memory. Using dynamic memory allocation, your program will access memory spaces as needed. This is in contrast to static data structure, wherein the programmer has to indicate a fix number of memory space to be used in the program.

 

 

 

41) The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

 

Answer:You can do this by using %% in the printf statement. For example, you can write printf(“10%%”) to have the output appear as 10% on the screen.

 

 

 

42) What are the advantages and disadvantages of a heap?

 

Answer:Storing data on the heap is slower than it would take when using the stack. However, the main advantage of using the heap is its flexibility. That’s because memory in this structure can be allocated and remove in any particular order. Slowness in the heap can be compensated if an algorithm was well designed and implemented.

 

 

 

 

 

******************************************************************

Basic Java Interview Questions

*******************************************************

Q1. Explain JVM, JRE and JDK?

JVM (Java Virtual Machine): It is an abstract machine. It is a specification that provides run-time environment in which java bytecode can be executed. It follows three notations:

 

Specification: It is a document that describes the implementation of the Java virtual machine. It is provided by Sun and other companies.

Implementation: It is a program that meets the requirements of JVM specification.

Runtime Instance: An instance of JVM is created whenever you write a java command on the command prompt and run the class.

JRE (Java Runtime Environment) : JRE refers to a runtime environment in which java bytecode can be executed. It implements the JVM (Java Virtual Machine) and provides all the class libraries and other support files that JVM uses at runtime. So JRE is a software package that contains what is required to run a Java program. Basically, it’s an implementation of the JVM which physically exists.

 

JDK(Java Development Kit) : It is the tool necessary to compile, document and package Java programs. The JDK completely includes JRE which contains tools for Java programmers. The Java Development Kit is provided free of charge. Along with JRE, it includes an interpreter/loader, a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development. In short, it contains JRE + development tools.

 

Refer to this below image and understand how exactly these components reside:

 

Components – Java Interview Questions – Edureka

 

Q2. Explain public static void main(String args[]).

public : Public is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.

static : It is a keyword in java which identifies it is class based i.e it can be accessed without creating the instance of a Class.

 

void : It is the return type of the method. Void defines the method which will not return any value.

 

main: It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.

 

String args[] : It is the parameter passed to the main method.

 

Q3. Why Java is platform independent?

Platform independent practically means “write once run anywhere”. Java is called so because of its byte codes which can run on any system irrespective of its underlying operating system.

 

Q4. Why java is not 100% Object-oriented?

Java is not 100% Object-oriented because it makes use of eight primitive datatypes such as boolean, byte, char, int, float, double, long, short which are not objects.

 

Q5. What are wrapper classes?

Wrapper classes converts the java primitives into the reference types (objects). Every primitive data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the primitive data type into an object of that class. Refer to the below image which displays different primitive type, wrapper class and constructor argument.

 

WrapperClass – Java Interview Questions – Edureka

 

Q6. What are constructors in Java?

In Java, constructor refers to a block of code which is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.

 

There are two types of constructors:

 

Default constructor

Parameterized constructor

Q7. What is singleton class and how can we make a class singleton?

Singleton class is a class whose only one instance can be created at any given time, in one JVM. A class can be made singleton by making its constructor private.

 

Q8. What is the difference between Array list and vector?

Array List Vector

Array List is not synchronized.        Vector is synchronized.

Array List is fast as it’s non-synchronized.     Vector is slow as it is thread safe.

If an element is inserted into the Array List, it increases its Array size by 50%.        Vector defaults to doubling size of its array.

Array List does not define the increment size.        Vector defines the increment size.

Array List can only use Iterator for traversing an Array List.   Except Hashtable, Vector is the only other class which uses both Enumeration and Iterator.

Q9. What is the difference between equals() and == ?

Equals() method is defined in Object class in Java and used for checking equality of two objects defined by business logic.

“==” or equality operator in Java is a binary operator provided by Java programming language and used to compare primitives and objects. public boolean equals(Object o) is the method provided by the Object class. The default implementation uses == operator to compare two objects. For example: method can be overridden like String class. equals() method is used to compare the values of two objects.

 

 

public class Equaltest {

public static void main(String[] args) {

String str1= new String(“ABCD”);

String str2= new String(“ABCD”);

if(Str1 == str2)

{

System.out.println(“String 1 == String 2 is true”);

}

else

{

System.out.println(“String 1 == String 2 is false”);

String Str3 = Str2;

if( Str2 == Str3)

{

System.out.println(“String 2 == String 3 is true”);

}

else

{

System.out.println(“String 2 == String 3 is false”);

}

if(Str1.equals(str2))

{

System.out.println(“String 1 equals string 2 is true”);

}

else

{

System.out.prinltn(“String 1 equals string 2 is false”);

}

}}

Q10. What are the differences between Heap and Stack Memory?

The major difference between Heap and Stack memory are:

 

 

Features  Stack       Heap

Memory   Stack memory is used only by one thread of execution.        Heap memory is used by all the parts of the application.

Access    Stack memory can’t be accessed by other threads.       Objects stored in the heap are globally accessible.

Memory Management     Follows LIFO manner to free memory.   Memory management is based on generation associated to each object.

Lifetime   Exists until the end of execution of the thread.       Heap memory lives from the start till the end of application execution.

Usage      Stack memory only contains local primitive and reference variables to objects in heap space.        Whenever an object is created, it’s always stored in the Heap space.

 

 

In case you are facing any challenges with these java interview questions, please comment your problems in the section below. Apart from this Java Interview Questions Blog, if you want to get trained from professionals on this technology, you can opt for a structured training from edureka! Click below to know more.

 

Get Started with Java

 

OOPS Java Interview Questions:

Q1. What is Polymorphism?

 

 

 

 

Polymorphism is briefly described as “one interface, many implementations”. Polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts – specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are two types of polymorphism:

 

Compile time polymorphism

Run time polymorphism

 

 

Compile time polymorphism is method overloading whereas Runtime time polymorphism is done using inheritance and interface.

 

Q2. What is runtime polymorphism or dynamic method dispatch?

In Java, 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 superclass. Let’s take a look at the example below to understand it better.

 

class Car {

void run()

{

System.out.println(“car is running”);

}

}

class Audi extends Car {

void run()

{

System.out.prinltn(“Audi is running safely with 100km”);

}

public static void main(String args[])

{

Car b= new Audi();    //upcasting

b.run();

}

}

Q3. What is the difference between abstract classes and interfaces?

Abstract Class Interfaces

An abstract class can provide complete, default code and/or just the details that have to be overridden.     An interface cannot provide any code at all,just the signature.

In case of abstract class, a class may extend only one abstract class. A Class may implement several interfaces.

An abstract class can have non-abstract methods.        All methods of an Interface are abstract.

An abstract class can have instance variables.      An Interface cannot have instance variables

An abstract class can have any visibility: public, private, protected.      An Interface visibility must be public (or) none.

If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly  If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method

An abstract class can contain constructors    An Interface cannot contain constructors

Abstract classes are fast Interfaces are slow as it requires extra indirection to find corresponding method in the actual class

Q4. What is method overloading and method overriding?

Method Overloading :

In Method Overloading, Methods of the same class shares the same name but each method must have different number of parameters or parameters having different types and order.

Method Overloading is to “add” or “extend” more to method’s behavior.

It is a compile time polymorphism.

The methods must have different signature.

It may or may not need inheritance in Method Overloading.

Let’s take a look at the example below to understand it better.

class Adder {

Static int add(int a, int b)

{

return a+b;

}

Static double add( double a, double b)

{

return a+b;

}

public static void main(String args[])

{

System.out.println(Adder.add(11,11));

System.out.println(Adder.add(12.3,12.6));

}}

Method Overriding:

In Method Overriding, sub class have the same method with same name and exactly the same number and type of parameters and same return type as a super class.

Method Overriding is to “Change” existing behavior of method.

It is a run time polymorphism.

The methods must have same signature.

It always requires inheritance in Method Overriding.

Let’s take a look at the example below to understand it better.

 

 

class Car {

void run(){

System.out.println(“car is running”);

}

Class Audi extends Car{

void run()

{

System.out.prinltn(“Audi is running safely with 100km”);

}

public static void main( String args[])

{

Car b=new Audi();

b.run();

}

}

Q5. 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 same return type and same method arguments in child class then it will hide the super class method; this is known as method hiding. Similarly, you cannot override a private method in sub class because it’s not accessible there. What you can do is create another private method with the same name in the child class. Let’s take a look at the example below to understand it better.

 

 

class Base {

private static void display() {

System.out.println(“Static or class method from Base”);

}

public void print() {

System.out.println(“Non-static or instance method from Base”);

}

class Derived extends Base {

private static void display() {

System.out.println(“Static or class method from Derived”);

}

public void print() {

System.out.println(“Non-static or instance method from Derived”);

}

public class test {

public static void main(String args[])

{

Base obj= new Derived();

obj1.display();

obj1.print();

}

}

Q6. What is multiple inheritance? Is it supported by Java?

MultipleInheritance – Java Interview Questions – EdurekaIf 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 multiple inheritance is that if multiple parent classes have a 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 as Diamond Problem.

 

 

 

Q7. What is association?

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 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 relationship can be one to one, One to many, many to one and many to many.

 

Q8. What do you mean by aggregation?

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

 

Q9. What is composition in Java?

Composition is again specialized form of Aggregation and we can call this as a “death” relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if parent object deletes all child object will also be deleted. Let’s take again an example of 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 house if we delete the house room will automatically delete.

 

In case you are facing any challenges with these java interview questions, please comment your problems in the section below. Apart from this Java Interview Questions Blog, if you want to get trained from professionals on this technology, you can opt for a structured training from edureka! Click below to know more.