logo
down
shadow

java. inheritance/polymorphism, quiz error?


java. inheritance/polymorphism, quiz error?

By : Andrew Seepes
Date : November 23 2020, 03:01 PM
This might help you Here what's happening is when you call Base b = new Derived() it first calls Derived() on derived class. Now as Derived class extends Base class every constructor of Derived class internally calls the default cunstructor of base class, similer to
code :
Derived() {
        super();
        addValue();
    }


Share : facebook icon twitter icon
Java inheritance vs polymorphism

Java inheritance vs polymorphism


By : Ankit_designer
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further For your first part of the question I think Wikipedia provides a good definition:
code :
public class ChooseMethod {
   public void doSomething(Number n){
    System.out.println("Number");
   }
}
public class MethodChooser {
   public static void main(String[] args) {
    ChooseMethod m = new ChooseMethod();
    m.doSomething(10);
   }
}
public void doSomething(Integer i) {
 System.out.println("Integer");
}
public class ChooseMethodA {
   public void doSomething(Number n){
    System.out.println("Number A");
   }
}
public class ChooseMethodB extends ChooseMethodA {  }
public class MethodChooser {
    public static void main(String[] args) {
        ChooseMethodA m = new ChooseMethodB();
        m.doSomething(10);
    }
}
public void doSomething(Number n){
    System.out.println("Number B");
}
Java-Inheritance and polymorphism

Java-Inheritance and polymorphism


By : odonkor
Date : March 29 2020, 07:55 AM
this will help
I don't understand why overridden version is invoked instead of the original version.
code :
class Developer{
    public writeCode{
         System.out.println("Supervisor will write the code here");
    }
}

class JrDeveloper extends Developer{
    @Override
    public writeCode{
         System.out.println("Jr.Developer will write code");
    }
}

class Test{

     public static void main(){
     Developer dev = new JrDeveloper();
     dev.writeCode();         // Do you really expect the Developer to write 
                              // the code or the Jr.Developer?
     }
}
Inheritance and Polymorphism in Java

Inheritance and Polymorphism in Java


By : Robbert Rietveld
Date : March 29 2020, 07:55 AM
To fix the issue you can do
Button btn1 = new imageButton(); What exactly is the datatype of the first instance?
inheritance and polymorphism java

inheritance and polymorphism java


By : mkywrench
Date : March 29 2020, 07:55 AM
help you fix your problem First of we have to make a distinction between an object and a variable. A variable of type Customer can hold a reference to any object of the the type Customer or any object that is of type derived from Customer. Assignment sets the variable to reference a different object. Assignment does not alter the object itself at all. By this reasoning, the assignment won't result in loss of data.
Now, you asked if an object of the base class can be assigned to a variable used to hold the derived type e.g. SubClass obj = new BaseClass(). This cannot be done as an object of the base class is not an object of a derived type. The other way around it is possible e.g. 'BaseClass obj = new SubClass()' as an object of a derived type is a object of the base class.
Inheritance & Polymorphism in Java

Inheritance & Polymorphism in Java


By : Adam Chippy Lowe
Date : March 29 2020, 07:55 AM
help you fix your problem You assignments are reversed in the constructor. You are not setting the instance attributes values using the input params and hence those attributes always have the default values.Change this
shadow
Privacy Policy - Terms - Contact Us © voile276.org