Become a GOLD member of Deccansoft and get access to 40+ courses!!
NewBatches/Webinars
Packages
Gold Membership
Bestseller
Microsoft Azure Suite & Suite Plus
Power Platform Acadamy
New
Azure DevOps Expert & Expert Plus
MS.NET Foundation For Beginners
MS.NET Full Stack Developer
UI / Web Development
SQL Server & MSBI Tools
Software Testing
Courses
MS.NET Courses (Includes Live Project)
Complete C#, OOPs and Windows Programing
ASP.NET MVC Online Training
ASP.NET WebForms
ASP.NET Core
WCF incl. Web Services and Remoting
WPF incl. MVVM and Prism
LINQ and Entity Framework
Live Project Training for Developing Enterprise Application
Live Project using Ntier Arch (.NET5 + EF Core + Angular)
Gold Membership
CareerStep IT Program
Client-side UI Technologies
Building Static Web Pages using HTML and CSS
JavaScript and HTML DOM
jQuery, AJAX and JSON
Building Interactive Web Pages using HTML5 and CSS3
BootStrap + Live Examples
AngularJS + Live Project
Angular + Typescript
ReactJS
KnockoutJS
Xamarin
SQL Server + MSBI
SQL Server 2017
Querying Data with Transact-SQL(70-761)
SQL Server Integration Service (SSIS)
SQL Server Reporting Service (SSRS)
SQL Service Analysis Service (SSAS)
Cloud Computing / Azure / AWS
AZ-900: Microsoft Azure Fundamentals
Azure Suite (AZ-104+AZ-204+AZ-305+ AZ-500)
AZ-104: Microsoft Azure Administrator
AZ-204: Developing Solutions for Microsoft Azure
AZ-305: Microsoft Azure Architect Technologies and Design
AZ-400: Microsoft Azure DevOps
DP-203: Data Engineering on Microsoft Azure
Amazon Web Services (AWS)
Testing Tools
Manual Testing
Selenium Testing with Java(Live Training)
SharePoint
SharePoint 2013
Microsoft Power Platform
Microsoft Power Platform
Data Analytics using PowerBI (DA-100)
DevOps
Docker
Kubernetes
Microservices using .NET Core
Others
C and Data Structure
Core Java
OOPs and C++
Advance Java
Python Programming
Complete Azure Training
Pricing
Videos
Testimonials
Azure Certification
Contact Us
Login
Login or Register
×
Sign In
Register
Forgot Password?
How did you find us
WhatsApp
YouTube
LinkedIn
Facebook
Telegram
Twitter
Google
Referred by Friend
Refresh
Input symbols
By clicking Register, you accept to the
terms and conditions
and that you have read our
privacy policy.
Recover Password
×
Submit
Enquiry Now
Where did you come to know about us
WhatsApp
YouTube
LinkedIn
Facebook
LinkedIn Ad
Email
Twitter
Google
Referred
Other
Refresh
Input symbols
Inheritance
Interview Questions and Answer
1. 1. program on same method call using different operation? class one { int one(int x){ return x*x;} } class two extends one { int one(int x) { return x*x*x*; } } class { two ref=new one(); ref.one(5); }
Options:
a. Incompatible types
b. 25
c. 125
d. 25 125
Reveal Answer
2. 2. Write a program to pass the values as arguments and accepting it. class A { final int res(int a, int b) { System.out.println(a+""+b); return 0; } class B extends A { int res(int a, int b){ System.out.println(a+""+b); return 1; } class Test { public static void main(String args[]) { B b=new B(); } System.out.print(b.res(1,2)); }
Options:
a. compile error
b. 1 2
c. 1
d. 2
Reveal Answer
3. 3.Write a program on inheritance and check weather the given object is instance of a class or not? class A{ } class B extends A{ } class C extends A{ } class X { A a1=new B(); if(a1 instanceof B) System.out.println(“I'm Class B”); else if(a1 instanceof A) System.out.println(“I'm Class A”); else if(a1 instanceof C) System.out.println(“I'm Class C”); else System.out.print(“no match”);
Options:
a. I'm Class A
b. I'm Class B
c. I'm Class C
d. no match
Reveal Answer
4. 4.write a program on inheritance where by creating an object and initialize data in it ? Class Test{ final int res(int a, int b) { return 0; } } Class Test1 extends Test { final int res(int a, int b) { return 1; } } Class x{ Test1 tes=new Test1(); System.out.println(tes.res(0,1)); }
Options:
a. 0
b. 1
c. compile error
d. exception
Reveal Answer
5. 5.write a program on inheritance and access the sub class from the super class. class A { A(int x){ } class B extends A{ } class Test{ public static void main(String args[]){ A a= new B(); System.out.print(“completed”); } }
Options:
a. completed
b. compile error
c. exception
d. displays empty
Reveal Answer
6. 6.write a program to accept the string by using constructor with similar parameters. class x { int i=0; public x(String s) { i=1; } class y extends x { public y(String s) { i=2; } public static void main(String args[]) { y z=new y(“hello”); System.out.println(y.i); } }
Options:
a. 0
b. 1
c. 2
d. compiler error
Reveal Answer
7. 7. Which of these keyword must be used to inherit a class?
Options:
a. super
b. this
c. extent
d. extends
Reveal Answer
8. 8. Which of these keywords is used to refer to member of base class from a sub class?
Options:
a. upper
b. super
c. this
d. None of the mentioned
Reveal Answer
9. 8. Which of these keywords is used to refer to member of base class from a sub class?
Options:
a. upper
b. super
c. this
d. None of the mentioned
Reveal Answer
10. 9. A class member declared protected becomes member of subclass of which type?
Options:
a. public member
b. private member
c. protected member
d. static member
Reveal Answer
11. 10. What is the output of this program? class A { int i; void display() { System.out.println(i); } } class B extends A { int j; void display() { System.out.println(j); } } class inheritance_demo { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }
Options:
a. 0
b. 1
c. 2
d. Compilation Error
Reveal Answer
12. 11.What is the output of this program? class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }
Options:
a. 2 2
b. 3 3
c. 2 3
d. 3 2
Reveal Answer
13. 12.What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }
Options:
a. 2 2
b. 3 3
c. Runtime Error
d. Compilation Error
Reveal Answer
14. 13.What is the output of this program? class A { public int i; public int j; A() { i = 1; j = 2; } } class B extends A { int a; B() { super(); } } class super_use { public static void main(String args[]) { B obj = new B(); System.out.println(obj.i + " " + obj.j) } }
Options:
a. 1 2
b. 2 1
c. Runtime Error
d. Compilation Error
Reveal Answer
15. 14. What is the output of this program? class A { public int i; protected int j; } class B extends A { int j; void display() { super.j = 3; System.out.println(i + " " + j); } } class Output { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }
Options:
a. 1 2
b. 2 1
c. 1 3
d. 3 1
Reveal Answer
16. 15.What is the result of compiling and running the following code? class Base { public Base() { System.out.print("Base"); } } public class Derived extends Base{ public Derived() { this("Examveda"); System.out.print("Derived"); } public Derived(String s){ System.out.print(s); } public static void main(String[] args){ new Derived(); } }
Options:
a. ExamvedaDerived
b. ExamvedaBaseDerived
c. BaseExamvedaDerived
d. ExamvedaDerivedBase
e. Compilation Error
Reveal Answer
17. 16.What is the output of the following program code? abstract class C1 { public C1(){ System.out.print(1); } } class C2 extends C1 { public C2() { System.out.print(2); } } class C3 extends C2{ public C3() { System.out.println(3); } } public class Test{ public static void main(String[] a){ new C3(); } }
Options:
a. 12
b. 23
c. 123
d. 321
Reveal Answer
18. 17.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(); } }
Options:
a. Compilation Error
b. Class One method1
c. Class Two method1
d. Throws a NoSuchMethodException at runtime.
e. E.None of these
Reveal Answer
19. 18.What is the result of compiling and running this program? class Mammal { void eat(Mammal m) { System.out.println("Mammal eats food"); } } class Cattle extends Mammal{ void eat(Cattle c) { System.out.println("Cattle eats hay"); } } class Horse extends Cattle { void eat(Horse h) { System.out.println("Horse eats hay"); } } public class Test { public static void main(String[] args){ Mammal h = new Horse(); Cattle c = new Horse(); c.eat(h); } }
Options:
a. prints "Mammal eats food"
b. prints "Cattle eats hay"
c. prints "Horse eats hay"
d. Class cast Exception at runtime.
e. None of these
Reveal Answer
20. 19.Determine the output: class A { public void method1() { System.out.print("Class A method1"); } } class B extends A { public void method2() { System.out.print("Class B method2"); } } class C extends B { public void method2() { System.out.print("Class C method2"); } public void method3() { System.out.print("Class C method3"); } } public class Test { public static void main(String args[]) { A a = new A(); C c = new C(); c.method2(); a = c; a.method3(); } }
Options:
a. Class B method2 Class C method3
b. Class C method2 Class C method3
c. Compilation Error
d. Runtime exception
e. None of these
Reveal Answer
21. 20.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()); } }
Options:
a. 30
b. 10
c. 40
d. 20
e. None of these
Reveal Answer
22. 21.What will be the output? class Parent { public void method() { System.out.println("Hi i am parent"); } } public class Child extends Parent { protected void method(){ System.out.println("Hi i am Child"); } public static void main(String args[]){ Child child = new Child(); child.method(); } }
Options:
a. Compiles successfully and print
b. Compiles successfully and print
c. Compile time error
d. Run Time error
e. None of This
Reveal Answer
23. 22.What will be the output? class One { final int a = 15; } class Two extends One { final int a = 20; } public class Test extends Two { final int a = 30; public static void main(String args[]){ Test t = new One(); System.out.print(t.a); } }
Options:
a. 15
b. 20
c. 30
d. Compiler Error
e. None of these
Reveal Answer
24. 23.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); } } }
Options:
a. Value-B 11
b. Value-B 10
c. Value-A 10
d. Value-A 11
e. None of these
Reveal Answer
25. 24.What will be the result after compiling this code? class SuperClass { public int doIt(String str, Integer... data)throws Exception{ String signature = "(String, Integer[])"; System.out.println(str + " " + signature); return 1; } } public class Test extends SuperClass { public int doIt(String str, Integer... data){ String signature = "(String, Integer[])"; System.out.println("Overridden: " + str + " " +signature); return 0; } public static void main(String... args){ SuperClass sb = new Test(); sb.doIt("hello", 3); } }
Options:
a. Overridden: hello (String, Integer[])
b. hello (String, Integer[])
c. Compilation fails
d. None of these
Reveal Answer
26. 25.what will bet he output of the following code? class A { A(String s) { } A() { } } class B extends A { B() { } B(String s) { super(s); } void test() { // insert code here } } Which of the below code can be insert at line 7 to make clean compilation ?
Options:
a. A a =new B();
b. A a = new B(5);
c. A a = new A(String s);
d. All of the above
e. None of these
Reveal Answer
27. 26.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(); } }
Options:
a. Value-A Name-B
b. Value-A Value-A
c. Value-A Name-C
d. Name-B Name-C
e. None of these
Reveal Answer
28. 27.Determine output: class A { public void printName(){ System.out.println("Name-A"); } } class B extends A{ public void printName(){ System.out.println("Name-B"); } } class C extends A { public void printName() { System.out.println("Name-C"); } } public class Test { public static void main (String[] args){ B b = new B(); C c = new C(); b = c; newPrint(b); } public static void newPrint(A a){ a.printName(); } }
Options:
a. Name B
b. Name C
c. Compilation fails due to an error on lines 5
d. Compilation fails due to an error on lines 9
e. None of these
Reveal Answer
29. 28.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(); } }
Options:
a. Value-A
b. Name-B
c. Value-A Name-B
d. Compilation fails - private methods can't be override
e. None of these
Reveal Answer
30. 29.What will be the result of compiling and running the given code? class A { int b=10; private A() { this.b=7; } int f() { return b; } } class B extends A { int b; } public class Test { public static void main(String[] args){ A a = new B(); System.out.println(a.f()); } }
Options:
a. Compilation Fails
b. Prints 0
c. Prints 10
d. None of these
Reveal Answer
31. 29.What will be the result of compiling and running the given code? class A { int b=10; private A() { this.b=7; } int f() { return b; } } class B extends A { int b; } public class Test { public static void main(String[] args){ A a = new B(); System.out.println(a.f()); } }
Options:
a. Compilation Fails
b. Prints 0
c. Prints 10
d. Prints 7
e. None of these
Reveal Answer
32. 30.What will be the result of compiling and executing the following program code? class Vehicle { public void printSound() { System.out.print("vehicle"); } } class Car extends Vehicle { public void printSound() { System.out.print("car"); } } class Bike extends Vehicle { public void printSound(){ System.out.print("bike"); } } public class Test { public static void main(String[] args){ Vehicle v = new Car(); Bike b = (Bike) v; v.printSound(); b.printSound(); } }
Options:
a. Compilation fails.
b. ClassCastException exception is thrown at runtime.
c. "vehiclecar" is printed.
d. "vehiclebike" is printed.
e. "carcar" is printed.
Reveal Answer
33. 31.Dermine output: class Small { public Small(){ System.out.print("a "); } } class Small2 extends Small { public Small2(){ System.out.print("b "); } } class Small3 extends Small2 { public Small3() { System.out.print("c "); } } public class Test { public static void main(String args[]){ new Small3(); } }
Options:
a. a
b. c
c. a b c
d. c b a
e. The code runs without output..
Reveal Answer
Packages
Gold Membership
Microsoft Azure Suite &Suite Plus
Azure DevOps Expert &Expert Plus
MS.NET Foundation For Beginners
MS.NET Full Stack Developer
UI / Web Development
SQL Server & MSBI Tools
Software Testing
Resources
Blog
Deccansoft
AzureA2Z
Wall of Fame
On-Job Tech Support
About
About BestDotNetTraining
About Trainer
Testimonials
FAQ
Other links
About Us
Contact Us
Leave us a feedback
Sitemap
Privacy Policy
Terms & Conditions
Proudly Powered by