-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavaQuestions.txt
67 lines (54 loc) · 2.87 KB
/
javaQuestions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
1. what is java? features of java ?
Java is a high-level and purely object oriented programming language.
It is platform independent, robust, secure, and multithreaded programming language
2. what is class and object in java ?
Class is not a real world entity. It is just a template or blueprint or
prototype from which objects are created. Class does not occupy memory.
object is a basic unit of Object-Oriented Programming and represents real life entities
3. what is constructor ?
A constructor is a special method that has same name as a class name
it is called automatically when object is created.
there are two types of constructors:
Default Constructor
Parameterized Constructor
4. what is this keyword ?
this keyword refers to current instance of object or a constructor.
it is used to eliminate the confusion between instance variable and parameters variable
5. what is static variable in java?
When a variable is declared as static, then a single copy of the variable is created
and shared among all objects at the class level. it saves memory and it can be access
using class name.
6. why multiple inheritance is not supported in java ?
The reason behind this is to prevent ambiguity.
Consider a case where class B extends class A and Class C and
both class A and C have the same method display().
Now java compiler cannot decide, which display method it should inherit.
To prevent such situation, multiple inheritances is not allowed in java
7. what is inheritance ?
It is the mechanism in java by which one class is allowed to inherit the features(fields and methods)
of another class. In Java, inheritance means creating new classes based on existing ones.
A class that inherits from another class can reuse the methods and fields of that class.
8. types of inheritance ?
i. Single Inheritance
ii. Multilevel Inheritance
iii. Hierarchical Inheritance
iv. Multiple Inheritance (Through Interfaces)
9. super keyword in java ?
it is used to call the parent class constructor and used to refer parent class instance variable
and also used to call parent class method.
10. what is polymorphism ?
The word polymorphism means having many forms
Polymorphism allows us to perform a single action in different ways. In other words,
polymorphism allows you to define one interface and have multiple implementations.
types of polymorphism:
i. Compile-time Polymorphism
This type of polymorphism is achieved by function overloading or operator overloading.
ii. Runtime Polymorphism
Method overriding
11. what is Encapsulation ?
Encapsulation is used to hide sensitive data from users
example by making variables private and providing public geter and seter methods to access
the private variable
12. Abstraction in java ?
Data abstraction is the process of hiding certain details and showing only essential information to the user.
Abstraction can be achieved with either abstract classes or interface