r/javahelp • u/Kodak419 • May 02 '20
A website/book that can help me practice complicated inheritance & polymorphism questions?
Hi , I have an upcoming test and the OO questions there are real tough. I would appreciate references to books or websites specializing in teaching university level inheritance and polymorphism
1
u/Kodak419 May 03 '20
public class A{
public void f(A a){
System.out.print("in A ");}}
public class B extends A{
//**write the method here
public static void main (String[] args){
B b = new B(); A a = new A();b.f(b); b.f(a);
}
}
Choose and explain. Which of the following methods can be inserted in the specified area of the code? and what will be the output of the program
1 . protected void f(A a){
System.out.print("in B ");
}
(a) in A in A (b) in B in A (c) in B in B (d)compilation error
______________________________________________
______________________________________________
public void f(A a){
System.out.print("in B");
throw new java.io.IOException();
}
(a) in A in A (b) in B in A (c) in B in B (d)compilation error
____________________________________________
______________________________________________
1
u/Kodak419 May 03 '20
Sure
1
u/Myron322020 May 03 '20
Apparently dont look like I can. I think I was flagged because I kept posting my website and I saw some jealous people hating.. what's the best way to contact you?
1
5
u/random_buddah May 03 '20
„Complicated“ is kinda relative. Do you have some samples of the tough question, just to get an idea of what you aim at?
1
u/Myron322020 May 03 '20
@kodak419 what do you need help with? Just understand inheritance and polymorphism? I will be glad to help
1
u/Kodak419 May 03 '20
I know the principles the problem is with the exercises. Which method overrides which? When does an object belong to the superclass? When is a subclass constructor and is used etc etc. The questions in these tests can get real intricate.
2
u/Myron322020 May 03 '20
Ok only these 2 questions correct? I'll love to explain the answers to you. Can I inbox u?
3
u/[deleted] May 03 '20
Complete Java Reference by Herbert Schildt.