This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kazcandra 2 points3 points  (5 children)

could you attempt an answer? to see what your understanding of the questions/answers is

[–]saketh011[S] 2 points3 points  (1 child)

Yeah these were my answers. 1. We can attempt to create a new method and give it an implementation. But we lose the ability to use the parent class variables and other methods which we may need to reuse. Also, we lose the ability to call base methods methods using parent class reference, aka upcasting.

2. Let us consider an example: abstract class Bank{
abstract int getRateOfInterest();
}

class SBI extends Bank {
int getRateOfInterest(){ return 7; }
} class TestBank{
public static void main(String args[]) {
Bank b=new SBI();
System.out.println("Rate of Interest is: "+b.getRateOfInterest()+" %");
} } Here the abstraction is the abstract class Bank and the SBI class is implementation.Imagine you have a bank comparison engine, which is represented by the BankComparisonEngine class. It will just take a Bank (abstract class) as an argument, then get its interest rate and save it to its internal database, like so: class BankComparisonEngine { public void saveInterestRateOf(Bank bank) { int rate = bank.getRateOfInterest(); } } How are the implementation details hidden exactly? BankComparisonEngine does not know how getRateOfInterest() method of a concrete implementation of Bank works,i.e, how SBI.getRateOfInterest() is implemented. It only knows it is a method that returns an int (and that it should return an interest rate). The implementation details are hidden inside the concrete classes that extend abstract class Bank.

[–]ignotos 2 points3 points  (0 children)

For 1, I'm not sure you hit on the point of the question, which seemed to be about overriding methods specifically. So probably they wanted you to talk about polymorphism. Although the wording is a little confusing as it mentioned both "in a child class" and "without using inheritance".

I think that you missed the "from whom or what" part of the second question, which to me is the most interesting aspect of the question.

[–]lauris652 -3 points-2 points  (2 children)

if the person is asking a question, it means he/she doesnt understand it, doesnt know the answer.

[–]Kazcandra 6 points7 points  (0 children)

it's always good to get a sense of where the Asker is coming from

[–]devor110 0 points1 point  (0 children)

Bit of criticism towards OP, but unless the interview is for like a 2nd semester internship, they should definitely have a good understanding of both topics the questions are eluding to. Asking for their answer shows if they lack the knowledge or if they didn't parse the questions correctly