Top 25 Most Popular Computer Science Interview Question and Answers

Computer Science Interview Question and Answers

Table of Contents

Most Popular Computer Science Interview Question and Answers for the Year 2020

Computer Science Interview Question and Answers

So you have finally found your dream job in Computer Science, in this Computer Science Interview Question and Answers, there are methods for how to crack the 2020 Computer Science interview. Every Computer Science interview is different and the scope of a job is different too. Below is the 25 most common 2020 Computer Science interview Questions that are asked mostly:

Q1. 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 filename (e.g. STUDENT.MARKS). A file name normally has primary and secondary names separated by a “.”(DOT).

Q2. 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.

Q3. 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 }}

Q4. What is a constructor?

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

Q5. What is the different OOPS principle?

The basic OOPS principle are as follows,

  1. Encapsulation
  2. Abstraction
  3. Inheritance
  4. Polymorphism

Q6. What is inheritance?

Inheritance is the property in which the property of a parent class(Superclass) is passed on to 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

}}

Q7. What is polymorphism?

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

Q8. What are the instance and class variables?

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

public class Abc{

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

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

……………………..

……………..

}

Q9. Compare method and constructor?

a) Constructor: Used to initialize the instance of a class.

a) Method: Used to perform some function or operation.

b) Constructor: Doesn’t have a return type.

b) Method: Has a return type.

Q10. 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.

Let us move to the next level of Computer Science Interview Question and Answers

Q11. What are the steps for creating the object?

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

Abc a= new Abc();

Q12. What is the different type of access modifiers?

There are four types of access modifiers as given below:-

  • 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

Q13. Which is the highest operator precedence in Java

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

Q14. What is an array?

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

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

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

Let us move to the next level of Computer Science Interview Question and Answers

Q16. Is the string class final?

Yes

Q17. What is a wrapper class?

To access the primitive data type as an object we use wrapper class. They are the following:-

Primitive Type  Wrapper class
BooleanBoolean
charCharacter
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble

Q18. 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 having the same method name and parameters (i.e., method signature) but one of the methods is in the parent class and the other is in the child class.

Q19. What are the 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 extends multiple classes.

Q20. What is the stream?

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

InputStream: Used to read data from a source.

OutPut Stream: Used to write data into a destination.

Let us move to the next level of Computer Science Interview Question and Answers

Q21. What is a Character stream?

Java Character stream is basically used to perform input and output for 16 bit Unicode. The main classes users are FileReader and FileWriter which internally uses FileInputStream and FileOutputStream so the basic difference is that FileReader and FileWriter read and writes two bites at a time respectively.

Before you leave,  Read important topic of Java on Wikipedia.

Q22. What is a Byte stream?

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

The main classes related to byte streams are FileInputStream and FileOutputStream.

Q23. What is an Interface?

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

Q24. Difference between class and interface?

Below are the difference between Interface and class:-

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.

Q25. What is an abstract class?

A class that contains the abstract keyword in a declaration is called an abstract class. The properties of the abstract class are as follows:-

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.

Related Articles

Responses