Top 25 Most Popular Computer Science Interview Question and Answers

Computer Science Interview Question and Answers

The team at GoApti has prepared this list of 25 computer science interview question and answers to strengthen your concepts and understanding.

Computer science is considered among the most essential segments today. It stands shoulder to shoulder with science, mathematics, finance, etc. 

Computer science is the study of algorithmic processes and computational machines. As a discipline, computer science spans a range of topics from theoretical studies of algorithms, computation and information to the practical issues of implementing computing systems in hardware and software. Computer science addresses any computational problems, especially information processes, such as control, communication, perception, learning, and intelligence.  Source: Wikipedia

1. What is a file?

A file is a named location that stores data or information permanently. A file is always stored inside a storage device using a filename (e.g. STUDENT.MARKS). A file name normally has primary and secondary names separated by a “.” (DOT).

2. What is a class?

A class is a blueprint from which objects are created. A class contains methods and variables associated with an instance of a class.

3. What is an object?

An object is an instance of a class. For example:

class Abc  { —– This is a class

int a; —— This is a variable

public Abc(); —- This is contractor

public static void main (String args[]) ——- This is a method

{ Abc a= new Abc(); —— This is object creation where ‘a’ is the reference variable or object name }}

4. What is a constructor?

A constructor is a method that is used to create an object of the class. There are two types of constructors: Default and Parameterized constructors.

5. What are the different OOPS principles?

The basic OOPS principles are:

  • Encapsulation.
  • Abstraction.
  • Inheritance.
  • Polymorphism.

6. What is inheritance?

Inheritance is the property in which the property of a parent class (superclass) is passed on to the child class (subclass). For example:

class Abc{ —– This is a class

int a; —— This is a variable

public void abc(){} — Methods

}class Xyz extends Abc —–(Extend is the keyword, Xyz is the subclass which inherits the properties of ABC parent class.)

{public static void main (String args[]) ——- This is a method

{Abc a= new Abc(); —— This is object creation where ‘a’ is the reference variable or object name


7. What is polymorphism?

Polymorphism is the ability of an object to take on multiple forms. The most commonly used polymorphism example in OOP is when a parent class reference is used to refer to a child class object.

8. What are the instance and class variables?

The instance variable belongs to a particular instance of that class whereas the class variable belongs to the class itself. A class variable is also known as a static variable. For example:

public class Abc{

public int a; …….. This is an instance variable

public static int a1;…….. This is a static or class variable



9. What are methods and constructors?

Constructor: Used to initialize the instance of a class. It doesn’t have a return type.

Method: Used to perform some function or operation. It has a return type

10. What is a singleton class?

Singleton class limits the number of objects created for a class to one but gives the flexibility of creating more objects if the situation changes.

11. What are the steps for creating the object?

An object is first declared then instantiated and at last defined. For example:

Abc a= new Abc();

12. What are the different types of access modifiers?

There are four types of access modifiers:

  • Visible to the overall package. No modifier needed.
  • Private – Visible to class only.
  • Public – Visible to the world.
  • Protected – Visible to package and subclass.

Also Read:Top 10 and Best Linux Interview Questions And Answers

13. Which operator has the highest precedence in Java?

The operator with the highest preference is the Postfix operator, i.e., () [].

14. What is an array?

The array is a container that holds a fixed number of similar data types.

15. What is the difference between equals() method and == operator?

The equals() is a method that matches the content of the strings, whereas == is an operator that matches the object or reference of the strings.

16. Is the string class final?


17. What is a wrapper class?

We use the wrapper class to access the primitive data type as an object.

Primitive type  Wrapper class
Boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double

18. What is the difference between overloading and overriding?

Overloading is when two or more methods in the same class have the same method name but different parameters, i.e., different method signatures.

Overriding is when two methods have the same method name and parameters, i.e., method signature. One of the methods is in the parent class and the other is in the child class.

19. What are multiple inheritances in Java?

Java supports multiple inheritances, i.e., the ability of a class to implement more than one interface. A class can implement multiple Interfaces but cannot extend multiple classes.

20. What is a stream?

A stream can be defined as the sequence of data. There are two types of streams:

Input Stream: Used to read data from a source.

Output Stream: Used to write data into a destination.

21. What is a Character stream?

Java Character stream used to perform input and output for 16 bit Unicode. The main classes used are FileReader and FileWriter which internally rely on FileInputStream and FileOutputStream. FileReader and FileWriter read and write two bites at a time respectively.

Also Read: Java on Wikipedia.

22. What is a Byte stream?

Java Byte stream is used to perform input and output for 8 bit Unicode.

The main classes related to the byte stream are FileInputStream and FileOutputStream.

23. What is an Interface?

The interface is a reference type in Java, similar to the class but it is a collection of abstract methods. A class can implement multiple interfaces.

24. What is the difference between class and interface?

The differences between interface and class are:

  • The interface cannot be instantiated.
  • An interface doesn’t have any constructors.
  • Interface only have abstract methods.
  • A class implements an interface and extends a class.
  • An interface can extend multiple interfaces.

25. What is an abstract class?

A class that contains the abstract keyword in its declaration is called an abstract class. The properties of the abstract class are:

  • Abstract classes may or may not contain abstract methods, but if a class has at least one abstract method, then it must be declared abstract.
  • The abstract class cannot be instantiated.
  • To use an abstract class, we have to inherit it from another class.
  • If we inherit an abstract class, then we have to provide implementations to all the abstract methods in it.

What’s your story about computer science? Are you aware of other important interview questions? Any interview tips and tricks to share? Do comment.

Related Articles