variable
http://www.witscale.com/ebook/Browsable/ebook065.htm
method -
final method cannot be overridden
class-
final class cannot be subclassed
Saturday, March 27, 2010
Friday, March 26, 2010
2- identifier naming
a) should not start with a number
b) can start with an alphabet $ _
c) java is case sensitive
b) can start with an alphabet $ _
c) java is case sensitive
1- source file naming convention
a) There can be only one or zero public class per file and any number of non public classes
b) If there is a public class then file name should match the public class name
c) There can be only one package statement and any number of import statements but package statement should be the first line and import statements should immediately follow if they are there
d) public class can be the first class or come in between or after any number of non public classes
e) there can be a main method in one or any number or classes in the source file
b) If there is a public class then file name should match the public class name
c) There can be only one package statement and any number of import statements but package statement should be the first line and import statements should immediately follow if they are there
d) public class can be the first class or come in between or after any number of non public classes
e) there can be a main method in one or any number or classes in the source file
6 - local variable
a) only final modifier can be used
b) has no default value so it has to be assigned a value before it can be used
b) has no default value so it has to be assigned a value before it can be used
5- this
a) used to refer to any member of same class or inherited member
b) actually no need to specifically use ' this . ' we can simply use the member name
c) this always refers to currently executing object
b) actually no need to specifically use ' this . ' we can simply use the member name
c) this always refers to currently executing object
10 - abstract
a) If an abstract method is not visible in a subclass then that subclass is abstract even if it implements a method with same name
b) If a class inherits a method with same name as abstract method and abstract method is visible to it, then it is non abstract even if the super class from which it has inherited is abstract due to a)
c) if anywhere in the inheritance hierarchy you have a non abstract class then all it's subclasses are also non abstract unless they define an abstract method
d) polymorphism and overriding work in the same way as non abstract method.
e) runtime error- java.lang.Abstract method error occurs when you try to invoke an abstract method.
particularly at compile time you can invoke an abstract method using abstract class reference but at runtime if the actual object does not have a valid overridden method then this error will happen
b) If a class inherits a method with same name as abstract method and abstract method is visible to it, then it is non abstract even if the super class from which it has inherited is abstract due to a)
c) if anywhere in the inheritance hierarchy you have a non abstract class then all it's subclasses are also non abstract unless they define an abstract method
d) polymorphism and overriding work in the same way as non abstract method.
e) runtime error- java.lang.Abstract method error occurs when you try to invoke an abstract method.
particularly at compile time you can invoke an abstract method using abstract class reference but at runtime if the actual object does not have a valid overridden method then this error will happen
9 - static
a) static methods when being redefined their visibility cannot be reduced.
b) Inside static methods super cannot be used. But inside non static method you can use super to call a static super class method.
c) static methods are inherited.
d) if a class has defined a static method or has an inherited a static method, then a nonstatic method with same name in the that class is not possible.
b) Inside static methods super cannot be used. But inside non static method you can use super to call a static super class method.
c) static methods are inherited.
d) if a class has defined a static method or has an inherited a static method, then a nonstatic method with same name in the that class is not possible.
8 - inheritance
a) In inheritance hierarchy if the visibility of a method or variable gets interrupted at any class then all the subclasses from that class will not inherit that method or variable but they can be accessed using .
b) We can override a normal method and redefine a static method. but in both cases we cannot reduce the visibility level. Subclasses will be able to inherit the last defined method but still they can use . operator to access the other methods earlier defined
c) A variable normal or static can be redefined (methods can only be overridden) and unlike methods they can be of lesser visibility modifier
The subclasses will only see the last defined variable but still they can use . operator to access the other variables earlier defined
b) We can override a normal method and redefine a static method. but in both cases we cannot reduce the visibility level. Subclasses will be able to inherit the last defined method but still they can use . operator to access the other methods earlier defined
c) A variable normal or static can be redefined (methods can only be overridden) and unlike methods they can be of lesser visibility modifier
The subclasses will only see the last defined variable but still they can use . operator to access the other variables earlier defined
7 - method : overriding and polymorphism
a) . operator can be used on any member at any place if it is accessible at that place (based on access modifier properties)
b) If at any place a . operator can be used on any super class method (how ever high it is in hierarchy) then only it can be overridden at that place
c) If you use super class reference polymorphically and call a method, then if the actual object (sub class) has overridden that method then actual object's method gets called at run time and if it has not overridden then the super class reference type's method is called at run time
d) subclass will have inherited method from super class as if it has defined it. But while checking for overriding of an inherited method check as if in the class where it has been defined it overrides or not, if it overrides then then subclass where it has been inherited is also a overridden method.
e) Ex. two cases - shown in diagram
b) If at any place a . operator can be used on any super class method (how ever high it is in hierarchy) then only it can be overridden at that place
c) If you use super class reference polymorphically and call a method, then if the actual object (sub class) has overridden that method then actual object's method gets called at run time and if it has not overridden then the super class reference type's method is called at run time
d) subclass will have inherited method from super class as if it has defined it. But while checking for overriding of an inherited method check as if in the class where it has been defined it overrides or not, if it overrides then then subclass where it has been inherited is also a overridden method.
e) Ex. two cases - shown in diagram
in the first case the public method1()* is not an override of method1() as method1() cannot be accessed using . operator in class2
in the second case the public method1()* is an override of method1() as method1() can be accessed using . operator in class3
f) so if use the reference type of class1 polymorphically but actual object is class2 then if you call method1() on the reference then method1() of class1 only gets called but if the actual object is class3 then public method1() * of class3 gets called
g) If you're using a superclass type object reference polymorphically (the actual object is actually a subclass of the reference type) -
at compile time -it is only checked if the super class has that method (abstract also ok)
at run time if the subclass has the overridden method then it is called else the super class reference type's method gets called.
at run time even if the sub class has the overridden method but is not accessible then super class reference type's method gets called
in the second case the public method1()* is an override of method1() as method1() can be accessed using . operator in class3
f) so if use the reference type of class1 polymorphically but actual object is class2 then if you call method1() on the reference then method1() of class1 only gets called but if the actual object is class3 then public method1() * of class3 gets called
g) If you're using a superclass type object reference polymorphically (the actual object is actually a subclass of the reference type) -
at compile time -it is only checked if the super class has that method (abstract also ok)
at run time if the subclass has the overridden method then it is called else the super class reference type's method gets called.
at run time even if the sub class has the overridden method but is not accessible then super class reference type's method gets called
4 - interface
a) access can be public or default
b) interfaces are implicitly abstract even if it is not specified
method-
a) are public and abstract even if specified or not
b) have no implementation end with ; instead of {}
c) cannot be static
d) cannot be final
variable
a) are public, static and final even if specified or not-- are constants
b) are assigned at the place of declaration and cannot be reassigned a new value at any other place
b) interfaces are implicitly abstract even if it is not specified
method-
a) are public and abstract even if specified or not
b) have no implementation end with ; instead of {}
c) cannot be static
d) cannot be final
variable
a) are public, static and final even if specified or not-- are constants
b) are assigned at the place of declaration and cannot be reassigned a new value at any other place
3- class
a) can have default or public access modifier
b) default can not be typed explicitly if typed will give error
b) default can not be typed explicitly if typed will give error
Friday, February 19, 2010
encounters of a new java learner
hi here im trying to de'scribe my encounters with java.. tricky ones...
- class- has access of default or public only...(this i didnot know and i worked for 10 months on java :0 was dumbstrcuk after reading it)
- if the inheritance flow is through packages..if at any stage a method becomes invisble to one class then its sub classes will also never see it..even though they would have if u remove the class in between which was not able to see.
- but for abstract class heirarchy through packages an abstract method (default acess) may not be visible in one class but it is visible in the subclasses in the visbility packages group.
- if u r using super class as a polymorphic reference to access a method..criterions that need to be justified are -
- the method should also be there in super class
- actual objects method would be called at run time if there exists a correctly overridden method or a method which is equal as overriding method but not an override officially since the overridden method is not visible else
- the method of the superclass reference runs
- always while accessing a method or instance variable through . reference check
- if you can access the class from the class where u r trying to
- if you can access the method from the class where u r trying to
Subscribe to:
Posts (Atom)