Home / Computer Science / Interview Stuff / Interview Stuff

Interview Stuff

C ++ Interview Questions

Q1).State the different types of linked lists?

ANS). The different types of linked list includes, single linked list, double linked list and circular linked list.

Q2).List the basic operations carried out in a linked list?

ANS). The basic operation carried out in a linked list includes

*Creation of a list
*Insertions of a node
*Declaration of a node
*Modification of a node
*Traversal of the list.

Q3). State the contents of a data field and a linked field in a linked list?

ANS). The data field contains the information and the link field or the next address field contains the address of the next node in the list.

Q4). Define a stack?

ANS) A stack is an ordered collection of elements in which insertions and deletions are restricted to one end. The end from which elements are added and/or removed is referred to as top of the stack. Stacks are also referred as “piles” and “push-down lists.

Q5) Define a queue?

ANS). a queue is an ordered collection of elements in which insertions and deletions are restricted to one end. The end from which elements are added and /or removed is referred to as to as the rear end, the end from which deletions are made is referred to as the front end.

Q6) State the differences between arrays and linked list?

ANS) Arrays: Size of any array is fixed . it is necessary to specify the number of elements in an array during declaration.
Insertion and deletions are difficult in an array.
It occupies less memory than a linked. List for the same number of elements.

Linked Lists:

Size of list is variable .it is not necessary to specify the number of elements in during declaration.
Insertions and deletions are carried out easily.
It occupies more memory.

Q7) State the difference between stacks and linked lists?

ANS) The difference between stacks and linked lists is that insertions and deletions may occur any where in a linked list but only at the top of the stack.

Q8) State the difference between queues and linked lists.

ANS) The difference between queues and linked lists in insertions and deletions may occur any where in a linked lists but queues insertions can be made only in the rear end and deletions can be made only in the front end.

Q9)State the difference between a structure in C and C++?

ANS).C Language structure: It can have only variables as members.
They do not permit data hiding. They do not allow the datatype to be treated as built in types.

C++structure : It can have both variables and functions as members. They permit data hiding.
They allow the structure data type to be treated as built-in types.

Q10)State the difference between a structure and class in c++?

The only difference between a structure and class in c++ is that by default , the members of a class are private while , by default the members of a structure are public.

Q11)State the difference between procedural and object oriented programming?

ANS) Procedural programming focus on functions and data separately whereas object oriented programming ties data and functions to gather into object FOCUSES ON the interaction among the objects.

Q12).what does the following preprocessor directive #includedo ?

ANS)It causes the contents of the iostream .h file to be substituted for this directive before final compilation.

Q13)What are member variables?

ANS) Variables of a class are called as member variables or data members.

Q14) What are member function?

ANS) The functions declared inside a class are called as number functions.

Q15). Can member data and member functions can be private?

ANS) Yes both member data and members functions can be private.

Q16) State the difference between a public and a private member of a class?

ANS)A public member is accessible from outside the class where as a private member cannot be accessed from outside the class.

Q17) What is the dot operator, and what is used for ?

The operator is the period operator, which is used to access the member of the class.

Q18) What is meant by data hiding?

Insulation of data from direct access by the program is called data hiding.

Q19)What is encapsulation?

ANS)The process of combining data and functions in a single unit is called as encapsulation.

’Q20)Which member functions are created automatically if they are not including in the class definition?

ANS),There are four class member functions that are created automatically .

they are

Default constructor

Copy constructors

Overload assignment operator

Destructor

Q21)What is the main use of constructors?

ANS)Constructors are used for initializing member data in class.

Q22). What is the main use of destructors?

ANS)Destructors are used for reinitializing the objects which are initialized by constructors.

Java Interview Questions

1) String is mutable or immutable in java?

Ans: In java all string are immutable. ( a mutable string can be changed but immutable string cannot be changed).

2) StringBuffer is thread safe or not?

Ans: A StringBuffer is thread safe because it is synchronized. StringBuffer object is mutable.

3)What is StringTokenizer?

Ans: StringTokenizer is a class in java.util package this allows the string into tokens (pieces).

4)What is StringBuffer?

Ans: The StringBuffer is a class provided by java which is used to represent characters that can be modified.

5)What is StringBuilder?

Ans: StringBuilder is class in java introduced in java5. It allows you to expand the number of characters that it encapsulates it you can specify a value for the maximum number of characters that it can hold. if you need to concatenate a large number of strings, appending to a StringBuilder object is more efficient.

6) What is String in java?

Ans: String is a class in Java and available in java.lang package.String is immutable and final in Java and JVM uses String Constant Pool to store all the String objects.

7) What is the operator is used to compare two strings?

Ans: equals() or equalsIgnoreCase() method should be used to compare two string objects in Java.

8) How to create String objects in java?

Ans: Creating string objects in java is of two types.

1.String s1 = new String(“java”);

2. String s1=”java”;

9). What does intern() method do in Java?

Ans: String object created by new() operator is by default not added in String pool as opposed to String literal the intern() method allows putting string object into pool.

10) What is the difference when String is gets created using literal or new() operator ?

Ans: When we create string with new() its created in heap and not added into string pool while String created using literal are created in String pool itself which exists in Perm area of heap.

11) Can we write multiple main() methods in java program?

Ans: Yes, we can write by override the main() method but there should be only one main() method with the standard signature like public static void main(String args[ ]).

12) What is transient in Java?

Ans: A transient is a key word which is used to a variable that may not be serialize.

13)Explain about main() method in java?

Ans: Public: This is the first method called by java environment when the program starts its execution. So the access specifier is public.

Static: Java environment should call this method without creating any instance, hence static is used.

Void: main() method does not return any thing so return type should be void.

14) Can we make abstract class as final?

Ans: Abstract class may not be declared as final.

15)Which package is import always by default in java program?

Ans: By default java.lang package is always imported.

16) What are the four main pillars of Object Oriented Programming?

Ans: Inheritance, Abstraction,Encapsulation and Polymorphism.

17) What is JVM?

Ans: In expansion of JVM is Java Virtual Machine. JVM is an abstract computing machine that enables a computer to run a Java program. There are three notions of the JVM specification, implementation and instance. The specification is a document that formally describes what is required of a JVM implementation.

18) What is a Singleton property in Java?

Ans: Singleton is good property, java has this property. Singleton is to control the object creation by creating constructor in private. This singleton is useful to keep only one instance per class at any time.

19) What is WORA?

Ans: Write Once Run Anywhere (WORA) This is a slogan for java. Means java can be developed on any device and compiled into a standard byte code and expected to run any where or any device / platform equipped with JVM.

20) List Java features?

Ans: Object Oriented, Robust,Secure,Simple,Platform Independent, Architectural neutral, Portable and Dynamic.

Logical Programs Useful at Interview

1. Write program to print the reverse of a number?

Finding of the reverse can be done in different ways, see the below.

Reverse of a number by using While loop:

import java.util.Scanner;

public class ReverseofNumberByWhile {
public int ReverseByWhile() {

int number = 0;
int reverse = 0;
System.out.println(“Enter a number to find its reverse: “);
Scanner in = new Scanner(System.in);
// To get the runtime input
number = in.nextInt();
while (number != 0) {
reverse = reverse * 10;
reverse = reverse + number % 10;
number = number / 10;
}

System.out.println(“Reverse of input “+number+” is “+reverse);
return reverse;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ReverseofNumberByWhile rev = new ReverseofNumberByWhile();
rev.ReverseByWhile();

}

}

Output is :

Enter a number to find its reverse:
123456
Reverse of input 123456 is 654321

Reverse of Number By using For Loop:

import java.util.Scanner;

public class ReverseofNumber {
int number;
int reverse = 0;
Scanner sr = new Scanner(System.in);

public int reverseByforloop() {
System.out.println(“Enter an intger value”);
number = sr.nextInt();

for (; number != 0; number /= 10) { // Initialization not required
int reminder = number % 10;
reverse = reverse * 10 + reminder;
}
System.out.println(“Reverse of by using for loop ” + number + ” “+ reverse);
return reverse;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ReverseofNumber rn = new ReverseofNumber();
rn.reverseByforloop();
}

}

Output:

Enter an integer value : 5678
Reverse of by using for loop : 8765

Reverse of Number By using For Recursion:

import java.util.Scanner;

public class ReverseByRecursion {
public static void reverseOfNumber(int input_number) {
if (input_number < 10) {
System.out.println(input_number);
return;
}
else {
System.out.print(input_number % 10);
//Method is calling itself: recursion
reverseOfNumber(input_number/10);
}
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int number=0;
System.out.println(“Enter a number to find its reverse: “);
Scanner sr = new Scanner(System.in);
number = sr.nextInt();
System.out.print(“Reverse of input”+ number+” is:”);
reverseOfNumber(number);
System.out.println();

}

}

Output is:

Enter a number to find its reverse: 4567
Reverse of input4567 is:7654

 

About GSK

Hi, i am Santosh Gadagamma, a tutor in Software Engineering and an enthusiast for sharing knowledge in Computer Science and other domains. I developed this site to share knowledge to all the aspirants of technologies like, Java, C/C++, DBMS/RDBMS, Bootstrap, Big Data, Javascript, Android, Spring, Hibernate, Struts and all levels of software project design, development, deployment, and maintenance. As a programmer I believe that, "The world now needs computers to function." Hope, this site guides you as a learning tool towards greater heights. I believe that Education has no end points and i wish to learn more in the process of teaching you.

Check Also

Interview Question-Java Virtual Machine

When a Java program is compiled it is converted to byte code which is then …