0% found this document useful (0 votes)
14 views3 pages

Guess The Output On Polymorphism

The document contains a series of Java programming questions related to method overloading and polymorphism. Each question presents code snippets that demonstrate different behaviors of method calls based on parameter types and inheritance. The focus is on understanding how Java resolves method calls in various scenarios, including the use of varargs, null arguments, and method overriding.

Uploaded by

premdeoker21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Guess The Output On Polymorphism

The document contains a series of Java programming questions related to method overloading and polymorphism. Each question presents code snippets that demonstrate different behaviors of method calls based on parameter types and inheritance. The focus is on understanding how Java resolves method calls in various scenarios, including the use of varargs, null arguments, and method overriding.

Uploaded by

premdeoker21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🔹 Guess the Output – Method Overloading & void m1(int a, double b) { [Link].

println("int-
Polymorphism double"); }
void m1(double a, int b) { [Link]("double-
Q1 int"); }
class Test { }
void show(int a) { [Link]("int"); } public class Main {
void show(long a) { [Link]("long"); } public static void main(String[] args) {
} Test t = new Test();
public class Main { t.m1(10, 20);
public static void main(String[] args) { }
Test t = new Test(); }
[Link](5); --------------------------------
} Q5
} class Test {
-------------------------------- void show(Number n) { [Link]("Number"); }
Q2 void show(Integer i) { [Link]("Integer"); }
class Test { }
void display(Object o) { [Link]("Object"); } public class Main {
void display(String s) { [Link]("String"); } public static void main(String[] args) {
} Test t = new Test();
public class Main { [Link](100);
public static void main(String[] args) { }
Test t = new Test(); }
[Link](null); --------------------------------
} Q6
} class Parent {
-------------------------------- void print() { [Link]("Parent"); }
Q3 }
class Parent { class Child extends Parent {
void print() { [Link]("Parent"); } void print() { [Link]("Child"); }
} }
class Child extends Parent { public class Main {
void print() { [Link]("Child"); } public static void main(String[] args) {
} Parent p = new Child();
public class Main { Child c = new Child();
public static void main(String[] args) { [Link]();
Parent p = new Child(); [Link]();
[Link](); }
} }
}
--------------------------------
--------------------------------
Q4
class Test {
Q7 Q10
class Test { class Test {
void show(int... x) { [Link]("Var-args"); } void show(String s, Object o) {
void show(int x) { [Link]("int"); } [Link]("String-Object"); }
} void show(Object o, String s) {
public class Main { [Link]("Object-String"); }
public static void main(String[] args) { }
Test t = new Test(); public class Main {
[Link](10); public static void main(String[] args) {
} Test t = new Test();
} [Link]("hello", "world");
-------------------------------- }
Q8 }
class A { --------------------------------
void display() { [Link]("A"); } Q11
} class Parent {
class B extends A { void test() { [Link]("Parent"); }
void display() { [Link]("B"); } }
} class Child extends Parent {
public class Main { void test() { [Link]("Child"); }
public static void main(String[] args) { }
A obj = new B(); public class Main {
[Link](); public static void main(String[] args) {
} Parent p = new Parent();
} Parent c = new Child();
-------------------------------- [Link]();
Q9 [Link]();
class Test { }
void m1(char c) { [Link]("char"); } }
void m1(int i) { [Link]("int"); } --------------------------------
} Q12
public class Main { class Test {
public static void main(String[] args) { void show(Object o) { [Link]("Object"); }
Test t = new Test(); void show(StringBuffer sb) {
t.m1('A'); [Link]("StringBuffer"); }
} }
} public class Main {
-------------------------------- public static void main(String[] args) {
Test t = new Test();
[Link](null);
}
}

--------------------------------
Q15
Q13

class Parent {
class A { static void print() { [Link]("Parent static"); }
void print() { [Link]("A"); } }
} class Child extends Parent {
class B extends A { static void print() { [Link]("Child static"); }
void print() { [Link]("B"); } }
} public class Main {
class C extends B { public static void main(String[] args) {
void print() { [Link]("C"); } Parent p = new Child();
} [Link]();
public class Main { }
public static void main(String[] args) { }
A obj = new C();
[Link]();
}
}

--------------------------------

Q14

class Test {
void show(int a) { [Link]("int"); }
void show(Integer a) { [Link]("Integer"); }
}
public class Main {
public static void main(String[] args) {
Test t = new Test();
[Link](10);
}
}

--------------------------------

You might also like