Updated June 16, 2023
Introduction to Computer Science Interview Questions and Answers
So you have finally found your dream job in Computer Science but are wondering how to crack the 2023 Computer Science interview and what could be the probable Computer Science Interview Questions. Every Computer Science interview is different, and the job scope is different too. Keeping this in mind, we have designed the most common Computer Science interview Questions and answers to help you get success in your interview.
Below are the 25 most common 2023 Computer Science Interview Questions that are asked mostly:
1. What is a file?
Answer:
A file is a named location that stores data or information permanently. A file is always stored inside a storage device using a file name (e.g., STUDENT.MARKS). A file name typically has a primary and secondary name separated by a “.” (DOT).
2. What is a class?
Answer:
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?
Answer:
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?
Answer:
A constructor is a method used to create an Object of a class. There are two types of constructor Default & Parameterized constructor.
5. What is the different OOPS principle?
Answer:
The basic OOPS principle are as follows,
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism
6. What is inheritance?
Answer:
Inheritance is a 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?
Answer:
Polymorphism is the ability of an object to take on multiple forms. Polymorphism is commonly used in OOP when a parent class reference refers to a child class object.
8. What are the instance and class variables?
Answer:
Instance variable belongs to a particular instance of that class, whereas Class variable. 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. Compare the method and constructor?
Answer:
Constructor: Used to initialize the instance of a class.
Method: Used to perform some function or operation.
Constructor: Doesn’t have a return type.
Method: Has a return type.
10. What is a singleton class?
Answer:
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?
Answer:
An object is first declared, then instantiated, and at last declared. For example
Abc a= new Abc();
12. What is the different type of access modifiers?
Answer:
There are four types of access modifiers, as given below:-
• Visible to the overall package. No modifier is needed.
• Private – Visible to class only.
• Public – Visible to the world.
• Protected – Visible to package and subclass.
13. Which is the highest operator precedence in Java
Answer:
The operator with the highest preference is the Postfix operator, i.e. () [].
14. What is an array?
Answer:
The array is a container with a fixed number of similar data types.
15. What is the difference between equals() and method and == operator?
Answer:
The equals() is a method that matches the content of the strings, whereas == is an operator and matches the object or reference of the strings.
16. Is string class final?
Answer:
Yes
17. What is a wrapper class?
Answer:
To access the primitive data type as an object, we use the wrapper class. They are the following:-
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?
Answer:
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), but one of the methods is in the parent class, and the other is in the child class.
19. What are multiple inheritances in Java?
Answer:
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?
Answer:
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.
21. What is a Character stream?
Answer:
Java Character stream is 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 write two bites at a time, respectively.
22. What is a Byte stream?
Answer:
Java Byte stream is used to perform input and output for 8-bit Unicode.
The main classes related to byte streams are FileInputStream and FileOutputStream.
23. What is an Interface?
Answer:
The Interface is a reference type in Java, similar to the class, but it’s a collection of abstract methods. A class can implement multiple interfaces.
24. What is the difference between class and Interface?
Answer:
Below are the difference between Interface and class:-
- The Interface cannot be instantiated.
- An interface doesn’t have any constructors.
- The Interface only has abstract methods.
- A class implements an interface and extends a class.
- An interface can extend multiple interfaces.
25. What is an abstract class?
Answer:
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, 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, we must provide implementations for all its abstract methods.
Recommended Article
This has been a comprehensive guide to the Computer Science Interview Questions and answers so that the candidate can crack down on these Computer Science Interview Questions easily. This article consists of all the top Computer Science Interview Questions and Answers. You may also look at the following articles to learn more –