Вы находитесь на странице: 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
5.java does not have multiple inheritance coz deadly diamond of death
6.polymorphic invocations aply only to instance methods not static
7.you extend a class then you can override all methods except final
8.jvm uses virtual method invocation to dynamically select the actual version of the method that
will run
9.overriding : argument match,return type match or sub type,access level less restrictive,can
thow unchecked but not checked unless they are sub types,CAN THROW NARROWER OR
FEWER exceptions ie can take less risks,can't override static methods but they can be redefined.
10.if you wnat to call super class's method instead of overriden method then use super
super.callMethod();
11.even though at runtime the overriden method is called at compile time the compiler assumes
that you are calling super class's method.
so there is a problem at compile time if your super class method declares an exception and the
subclass 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 by looking at object,which overloaded
method to call is decided at compile time by looking at the ref type.
14.so polymorphism does come into pplay only for overriden methods.
15.you have Animal a =new Dog();
cool you can achieve polymorphism but what if u want to call dog's emthod
you cast a to Dog.
compiler trusts us when we do
Dog d = (Dog)a;

even if we do
Animal a = new Animal();
Dog d = (Dog)a; //incoreect but not detected at compile time
String s = "a";
Animal a = (Animal)s;//detected at compile time
16.changing animal to Dog is downcasting
downcasting is exlicit ,upcasting is implicit
17.abstract class Ball implements Bounceable{}

//correct

18.class A imlements B{}


class C extends A implements B{} //didn't have to specify the implementing class but its ok
19.covariant returns
return subtypes
20.public Button doStuff(){
return null;
}
21.every class including the abstract class must have a constructor.
22.private constructor then a static method must provide access to object created within the class.
23.u cannot make a call to instance methods or access an instance variable unless the call to
super completes inside the constructctor
24.interfaces do not have constructors,they are not ppart of object's inheritance tree
25.the only way a constructor can be invoked is from another constructor
26.default constructor : has same access modifier as class,no args ,no arg call to super
27.constructors are never inherited,overridden.
28.constructor uses this("alok"); to invoke other overloaded constructors.
29.static variables get default values like instance variables.
30.coupling : oo principle most closely associated with making sure that classes know about
other classes only through their API's
cohesion : oo princile most closely associated with making sure that a class is designed with a

single well focussed purpose.


`
30.coupling :
i.degree to which one class knows about other class.
ii.loose coupling : if the only knowledge class A has about class B is what class B has exposed
thru its interface
iii.tight coupling : if class A relies on parts of class B that r not part of class B's interface
cohesion : oo principle most closely associated with making sure that a class is designed with a
single well focussed purpose.
i.degree to which a class has a single well focussed purpose
ii.highly cohesive classes are easy to maintain and less frequently changed
iii.high cohesive classes are also reusable.
Encapsulation is the OO principle most closely associated with hiding implementation details.
Coupling is the OO principle most closely associated with making sure that classes know about
other classes only through their APIs.
Cohesion is the OO principle most closely associated with making sure that a class is designed
with a single, well-focused purpose.
Polymorphism is the OO principle most closely associated with allowing a single object to be
seen as having many types.

Вам также может понравиться