Java Interview Questions Flashcards

1
Q

What is a class?

A
  1. A blueprint or outline/ template used for creating objects. (and to define object data types and methods
  2. doesn’t consume any space in memory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an object?

A
  1. an instance of a class
  2. Any entity that has state and behavior For example a chair, pen, table, keyboard, bike, etc. It can be physical or logical.
  3. An ______ contains an address and takes up some space in memory.
  4. _____can communicate without knowing the details of each other’s data or code. The only necessary thing is the type of message accepted and the type of response returned by the objects.

5*

  1. Example: A dog is an object because it has states like color, name, breed, etc. as well as behaviors like wagging the tail, barking, eating, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

any entity that has ____ and behavior is an ____

A

state, object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

An _____ contains an address and takes up _____ in __________.

A

object, space, memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

____ can communicate without knowing the ____ of each other’s ____ or code. The only necessary thing is the ____ of message accepted and the type of ____ returned by the objects.

A

Objects, details, data, type, response

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In java, a _____ is just like a method but without the ____ type.

A

constructor, return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

_____ _____ in Java is a technique of having more than one _____ with different ____ ____. They are arranged in a way that each ____ performs a different ___. They are differentiated by the compiler by the number of parameters in the list and their ____.

A

Constructor overloading in Java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A constructor is used to ____ the state of an ____.

A

initialize, object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. A constructor is used to ___ the state of an object.
  2. A constructor must not have a ____ type.
  3. The constructor is ____ ____.
  4. The Java ___ provides a ____ constructor if you don’t have any constructor in a class.
  5. The constructor name must be same as the class name.
A
  1. A constructor is used to initialize the state of an object.
  2. A constructor must not have a return type.
  3. The constructor is invoked implicitly.
  4. The Java compiler provides a default constructor if you don’t have any constructor in a class.
  5. The constructor name must be same as the class name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The constructor is ____ ____.

A

invoked, implicitly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. A method is used to ____ the behavior of an object.
  2. A method must have a ___ type.
  3. The method is invoked ____.
  4. The method is ___ provided by the compiler in any case.
  5. The method name may or may not be same as ____ name.
A
  1. A method is used to expose the behavior of an object.
  2. A method must have a return type.
  3. The method is invoked explicitly.
  4. The method is not provided by the compiler in any case.
  5. The method name may or may not be same as class name.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A method is used to ____ the behavior of an object.

A

expose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The method is invoked ____.

A

explicitly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

in a method, the method ___ may or may not be the same as a ___.

A

name, class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Object oriented programming?

A
  1. it is a methodology or paradigm to design a program using Classes and Objects
  2. It simplifies the software development and maintenance by providing some concepts:
    classes, objects, abstraction, encapsulation, inheritance, polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are classes used for in Java?

A

Classes are used to create objects and define the object’s data types (fields) and methods (behaviors).

17
Q

What is a method?

A
  1. coordinated sequence of instructions that will be carried out when requested
  2. Other languages outside of java may call these functions.
  3. They give functionality to our class or its object
18
Q

What are the 4 access modifiers

A

private, public, protected, (default)

19
Q

What is Inheritance?

A
  1. Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part of OOPs (Object Oriented programming system).
  2. The idea behind inheritance in Java is that you can create new classes that are built upon existing classes. 3. When you inherit from an existing class, you can reuse methods and fields of the parent class.
  3. Moreover, you can add new methods and fields in your current class also.
  4. Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
20
Q
  1. Inheritance in Java is a mechanism in which one object acquires all the ____ and _____ of a parent object. It is an important part of OOPs (Object Oriented programming system).
  2. The idea behind inheritance in Java is that you can create ____classes that are built upon existing classes. 3. When you inherit from an existing class, you can reuse ____ and ____ of the parent class.
  3. Moreover, you can add new methods and fields in your current class also.
  4. Inheritance represents the IS-A relationship which is also known as a _____ - _____ relationship.
A
  1. Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part of OOPs (Object Oriented programming system).
  2. The idea behind inheritance in Java is that you can create new classes that are built upon existing classes. 3. When you inherit from an existing class, you can reuse methods and fields of the parent class.
  3. Moreover, you can add new methods and fields in your current class also.
  4. Inheritance represents the IS-A relationship which is also known as a parent-child relationship.
21
Q

Advantages of inheritance

A
  1. Code reusability

2. For Method Overriding(so runtime polymorphism can be achieved).

22
Q

Super Class/Parent Class

A

the class from where a subclass inherits the features. It is also called a base class or a parent class.

23
Q

Reusability

A

reusability is a mechanism which facilitates you to reuse the fields and methods of the existing class when you create a new class. You can use the same fields and methods already defined in the previous class.

24
Q

As the name specifies, reusability is a mechanism which facilitates you to reuse the ____ and ____ of the ____ class when you create a new class. You can use the same fields and methods already defined in the ____ class.

A

fields and methods, existing class, previous class

25
Q

Class:

A

Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.

26
Q

The extends keyword indicates that you are making a ____class that derives from an ____ class. The meaning of “extends” is to increase the _____.

A

The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of “extends” is to increase the functionality.