Java notes
Java notes
Q 3. What is inheritance?
Ans: Inheritance is a mechanism where a new class
(subclass or derived class) inherits properties and
behaviors from an existing class (superclass or base
class).
I
I
i
..., ~
. - --= ..,.~" --
;'", : J-, / "·--:. 'Ii~;.--~, r '
.. >~•..c. ,- J '
~ J__·! /~••
.J.:-. - 1-"-"l'w'
~ 7
I
~ - - c. --- -xr_as- -- -"-
I Compile T1me
) ',,
Run Time
/ '·.,_
/
,I "-,
r-----31__...----:----,
Function perator
Overloading ~ rload ing
Q 5. What is a constructor?
Ans: A constructor is a special method that is
automatically called when an object is created.
Interaction
Public Methods 1 -+------..
Interface
Private Data
Private Methods
Has-A IS-A
• •
Engine Vehicle
2,.•
Q 14. What is method hiding?
Ans: Method hiding is a concept in object-oriented
programming where a subclass defines a method
with the same name as a method in its superclass,
but the subclass method doesn't override the
superclass method.
.s (
l:! )
~
'5
{ this (n:11nel:
)
-
:J c■naon■
■rgement
conalNctor
)
Stud•nl ( Slt1ng rutme,lnt rollno) II parameterlz.ad construct.or
S
5
iu
U Student !String nilmo I
(
, _ _ _ this (I;
.
E
:,
!j
)
publlc atrulc void main !Siring n,vs( ) )
t
{
Slud41nt • • now Stuckn1 ( •J ohn" •76);
)
Q 16. What is the diamond problem in multiple
inheritance?
Ans: The diamond problem occurs in languages that
support multiple inheritance, where a class inherits
from two classes that have a common base class.
Exte~
( Class A ] ~ ends
[ Cla ss B
l [ Class C
l
Extend\ [ Class D
]~ ends
~=)
DSAwtth DSA&Syatem
System Design Deltgnwtth
(HLD • LLD) FullStack
Q 21. What is the SOLID principle?
Ans: The SOLID principle is an acronym for a set of design
principles that promote maintainable and scalable
code:
S J-1H · - · - · · 11BYQ1iur@+
Open Closed Principle
·-I