Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Download 1.52 Mb.
Pdf ko'rish
bet5/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   2   3   4   5   6   7   8   9   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

facebook.com/vibrantpublishers



SECTION
01
CORE JAVA
JAVA 8
JAVA 9
HUMAN RESOURCE



001.
CHAPTER
01
OOPs Concepts
Explain method overloading and method overriding.
Answer:
Method overloading occurs when there are two or more methods
in a class with the same name but with different number/type of
arguments. The following code demonstrates this:
public class Calculator {
public int add (int a, int b) {
return a+b;
}
public double add (double a, double b) {
return a+b;
}
public int add (int a) {
return a+a;
}
}
Method overriding occurs when there is a method in a sub–class
that has the same name and number of arguments as a super–
class method. The following code demonstrates this:
public class Animal {
public void saySomething () {
System.out.println(“I am an animal”);


002.
a.
b.
c.
d.
e.
003.
}
}
public class Dog extends Animal {
public void saySomething () {
System.out.println(“I am a dog”);
}
}
Explain the benefits of OOPs.
Answer:
Following are the benefits of OOPs:
Reusability: OOPs principles like Inheritance, Composition
and polymorphism help in reusing existing code
Extensibility: Code written using OOPs principles like
Inheritance makes code extensible

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling