SCJP chapter 2

Embed Size (px)

Citation preview

  • 8/18/2019 SCJP chapter 2

    1/3

    1.why inheritance : reuse,polymorphism

    2. promote good oo cause you don't have one class that does gazillion diff things

    3.is a : extends imlements

    4.has a : reference

    .!ava does not have multiple inheritance coz deadly diamond of death

    ".polymorphic invocations aply only to instance methods not static

    #.you extend a class then you can override all methods except final

    $.!vm uses virtual method invocation to dynamically select the actual version of the method that

    will run

    %.overriding : argument match,return type match or su& type,access level less restrictive,can

    thow uncheced &ut not checed unless they are su& types,()* +-/ *)--/0- -0/0- exceptions ie can tae less riss,can't override static methods &ut they can &e redefined.

    1.if you wnat to call super class's method instead of overriden method then use super 

    super.callethod56

    11.even though at runtime the overriden method is called at compile time the compiler assumesthat you are calling super class's method.

    so there is a pro&lem at compile time if your super class method declares an exception and thesu&class does not

    12.overloaded methods: must change argument list,return type,access,excepptions can change

    13.which overriden method is called is decided at runtime &y looing at o&!ect,which overloaded

    method to call is decided at compile time &y looing at the ref type.

    14.so polymorphism does come into pplay only for overriden methods.

    1.you have )nimal a 7new 8og56

    cool you can achieve polymorphism &ut what if u want to call dog's emthod

    you cast a to 8og.

    compiler trusts us when we do

    8og d 7 8og5a6

  • 8/18/2019 SCJP chapter 2

    2/3

    even if we do

    )nimal a 7 new )nimal56

    8og d 7 8og5a6 99incoreect &ut not detected at compile time

    tring s 7 ;a;6

    )nimal a 7 )nimal5s699detected at compile time

    1".changing animal to 8og is downcasting

    downcasting is exlicit ,upcasting is implicit

    1#.a&stract class

  • 8/18/2019 SCJP chapter 2

    3/3

    single well focussed purpose.

    A

    3.coupling :

    i.degree to which one class nows a&out other class.

    ii.loose coupling : if the only nowledge class ) has a&out class < is what class < has exposedthru its interface

    iii.tight coupling : if class ) relies on parts of class < that r not part of class