15 Matching Annotations
  1. Apr 2025
    1. actual method that is called depends on the actual type of the object.

      eg: 2 toString() methods, one of class Rectangle, other of class Square. varName.toString() calls rectangles toString() method

    2. the compiler uses the declared type to check that the methods you are trying to use are available to an object of that type.

      you cant access methods that are in the subclass if your object is declared as type superclass.

      Superclasses don't have knowledge or access to subclasses!!

    1. Shape reference variable can hold a Rectangle or Square object

      You can only set references in a superclass => subclass or subclass1 => subclass1 way.

      (down the hierarchy, (parent to child) or same hierarchic level (same child to same child) NEVER UP THE HEIRARCHY)

    1. super

      Just a way to refer to anything from the superclass.

      Eg: you want to override a method from the superclass in the subclass but need the calculated value from the superclass. you access that method with a Super.methodName() inside the overriden methodName() in the subclass and do whatever to that value. Overrides Super keyword

    2. unlike when we call a constructor with new, a call to super doesn’t create a new object.

      Using super() allows you to call the constructor of the superclass to instantiate private fields of the subclass.

      Used in the subclass's constructor

      (@)override public int SomeClass(int width, int heigh, int whateverElse){ return super( width, height, whateverElse) + this.width + this.height + whateverElse; } (psa ignore brackets at the at symbol)

    3. the chain of super calls from each subclass to its superclass ends in the no-argument constructor of java.lang.Object

      Ends the subclass to superclass no argument constructor calls using super() until it reaches the Cosmit Superclass or the Object Class

    4. constructor doesn’t start with a call to super Java will automatically insert a call to super with no arguments.

      Makes sure all instance variables are properly initialized before object use.

    5. cannot access the private instance variables of the superclass directly.

      side note: Fields (instance variables) can not be modified polymorphically, but can be inherited.

      meaning, you can not override instance variables, but you can inherit them from the superclass.

    1. overriding a method confused with overloading

      overRIDE -> SAME method NAME AND SIGNATURE, different body. overLOAD -> SAME method NAME and DIFFERENT SIGNATURE, different body (parameters)