Question 1 of 25
Hints left: 3
Q1
What will be the output of the following Java code? class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x = 0; this.y = 0; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 2; double b = 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + " " + obj.y); } }
Q2
What will be the output? interface A{ public void method1(); } class One implements A{ public void method1(){ System.out.println("Class One method1"); } } class Two extends One{ public void method1(){ System.out.println("Class Two method1"); } } public class Test extends Two{ public static void main(String[] args){ A a = new Two(); a.method1(); } }
Q3
____________ method cannot be overridden.
Q4
What will be the output of the following Java code? class A { public void m1 (int i,float f) { System.out.println(" int float method"); } public void m1(float f,int i); { System.out.println("float int method"); } public static void main(String[]args) { A a=new A(); a.m1(20,20); } }
Q5
What is the output for the below code? class A{ private void printName(){ System.out.println("Value-A"); } } class B extends A{ public void printName(){ System.out.println("Name-B"); } } public class Test{ public static void main (String[] args){ B b = new B(); b.printName(); } }
Q6
What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
Q7
What will be the output of the following Java program? final class A { int i; } class B extends A { int j; System.out.println(j + " " + i); } class inheritance { public static void main(String args[]) { B obj = new B(); obj.display(); } }
Q8
Which of these is correct about passing an argument by call-by-value process?
Q9
What will be printed after executing following program code? class Base{ int value = 0; Base(){ addValue(); } void addValue(){ value += 10; } int getValue(){ return value; } } class Derived extends Base{ Derived(){ addValue(); } void addValue(){ value += 20; } } public class Test{ public static void main(String[] args){ Base b = new Derived(); System.out.println(b.getValue()); } }
Q10
What will be the output of the following Java code? class overload { int x; int y; void add(int a) { x = a + 1; } void add(int a , int b) { x = a + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 0; obj.add(6, 7); System.out.println(obj.x); } }
Q11
What will be the output? class A{ static void method(){ System.out.println("Class A method"); } } class B extends A{ static void method(){ System.out.println("Class B method"); } } public class Test{ public static void main(String args[]){ A a = new B(); a.method(); } }
Q12
What will be the output of the following Java program? class Alligator { public static void main(String[] args) { int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}}; int [][]y = x; System.out.println(y[2][1]); } }
Q13
What will be the output? class A{ int i = 10; public void printValue(){ System.out.print("Value-A"); } } class B extends A{ int i = 12; public void printValue(){ System.out.print("Value-B"); } } public class Test{ public static void main(String args[]){ A a = new B(); a.printValue(); System.out.print(a.i); } }
Q14
What is the process of defining two or more methods within same class that have same name but different parameters declaration?
Q15
What is the output for the below code? class A{ public A(){ System.out.println("A"); } public A(int i){ this(); System.out.println(i); } } class B extends A{ public B(){ System.out.println("B"); } public B(int i){ this(); System.out.println(i+3); } } public class Test{ public static void main (String[] args){ new B(5); } }
Q16
What is the process of defining a method in terms of itself, that is a method that calls itself?
Q17
Determine output: class A{ public void printValue(){ System.out.println("Value-A"); } } class B extends A{ public void printNameB(){ System.out.println("Name-B"); } } class C extends A{ public void printNameC(){ System.out.println("Name-C"); } } public class Test{ public static void main (String[] args){ B b = new B(); C c = new C(); newPrint(b); newPrint(c); } public static void newPrint(A a){ a.printValue(); } }
Q18
What will be the output of the following Java code? class overload { int x; int y; void add(int a) { x = a + 1; } void add(int a, int b) { x = a + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 0; obj.add(6); System.out.println(obj.x); } }
Q19
What will be the output of the following Java code? class test { int a; int b; test(int i, int j) { a = i; b = j; } void meth(test o) { o.a *= 2; O.b /= 2; } } class Output { public static void main(String args[]) { test obj = new test(10 , 20); obj.meth(obj); System.out.println(obj.a + " " + obj.b); } }
Q20
What is the output for the below code? public class Test{ public static void printValue(int i, int j, int k){ System.out.println("int"); } public static void printValue(byte...b){ System.out.println("long"); } public static void main(String... args){ byte b = 9; printValue(b,b,b); } }
Q21
Which of these keywords can be used to prevent Method overriding?
Q22
what is the result of the following piece of code: public class Person{ public void talk(){ System.out.print("I am a Person"); } } public class Student extends Person{ public void talk(){ System.out.print("I am a Student"); } } public class Test{ public static void main(String args[]){ Person p = new Student(); p.talk(); } }
Q23
What will be the output of the following program code? class Rectangle{ public int area(int length, int width){ return length*width; } } class Square extends Rectangle{ public int area(long length, long width){ return (int) Math.pow(length, 2); } } public class Test{ public static void main(String args[]){ Square r = new Square(); System.out.println(r.area(5 , 4)); } }
Q24
Which of these is supported by method overriding in Java?
Q25
Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?