Professional Documents
Culture Documents
class Main {
public static void main(String args[]) {
try {
throw new Test();
}
catch(Test t) {
System.out.println("Got the Test Exception");
}
finally {
System.out.println("Inside finally block ");
}
}
}
2. class Main {
public static void main(String args[]) {
int x = 0;
int y = 10;
int z = y/x;
}
}
3. class Test
{
String str = "a";
void A()
{
try
{
str +="b";
B();
}
catch (Exception e)
{
str += "c";
}
}
str += "f";
void display()
{
System.out.println(str);
}
public static void main(String[] args)
{ Test object = new Test();
object.A();
object.display();
}
(A) abdef
(B) abdec
(C) abdefc
4. Please identify the error in the below code?
interface A
{
private int i;
}
Interface A {
Public int i ()
class Main {
Output:
Part B: 2*5= 10
ANS:-
2. What is method overriding? What is polymorphism? How are they related? What is runtime
polymorphism
ANS:- Method overriding means having two methods with the same method name and
parameters .One of the methods is in the parent class and the other is in the child class.Overriding
allows a child class to provide a specific implementation of method that is already provided its
parent class.
Polymorphism in Java is a concept by which we can perform a single action in different ways.
Polymorphism is derived from 2 Greek words: poly and morphs. The word "poly" means many and
"morphs" means forms. So polymorphism means many forms.There are two types of polymorphism in
Java: compile-time polymorphism and runtime polymorphism.