Академический Документы
Профессиональный Документы
Культура Документы
Tip: Make the fields private and accessor methods public if they are intended for the users of the class.
Make the fields or method protected if they are intended for extenders of the class.
Dynamic Binding: When compiler is not able to resolve the call/binding at compile time, such binding is
known as Dynamic or late Binding( occurs during Runtime). Overriding is a perfect example of dynamic
binding as in overriding both parent and child classes have same method.
Casting : used to convert an object of one class type to another within an inheritance hierarchy. 2 types
of casting : explicit and implicit.
Encapsulation: Encapsulation in Java is a me chanism of wrapping the data (variables) and code acting on
the data (methods) together as as single unit. In encapsulation the variables of a class will b e hidden
from other classes, and can be accessed only through the methods of their current class, therefore it is
also known as data hiding.
Polymorphism: refers to Javas ability to use base-class variables to refer to subclass objects, keep track
of which subclass an object belongs to, and use overridden methods of the subclass even though the
subclass isnt known when the program is compiled. Whenever a parameter calls for a particular type,
you can use an object created from a subclass of that type instead. (Remember print method for cats
and dogs, subclasses of animal).
An abstract class is a class that is declared using the abstract keyword. An abstract class cannot be
instantiated. It can be used only as a super-class for those classes that extend the abstract class. The
default functionality of the class still exists, with its fields, methods and constructors being accessed in
the same way as with the other classes.
Moreover, an abstract class may contain methods without any implementation, called abs tract
methods. The declaration of an abstract method starts with the abstract keyword and ends with a
semicolon, instead of the methods body. If a class contains an abstract method, either declared or
inherited, it must be declared as an abstract class.
A class that extends an abstract class must implement all its abstract methods (if any). Otherwise, the
sub-class must be declared as abstract as well. Finally, any implementation of an abstract method can be
overridden by additional sub-classes.
Last things to mention are that abstract classes can also implement methods, despite providing just
their signature and that an abstract class may have static fields and static methods. The purpose of an
abstract class is to specify the default functionality of an object and let its sub-classes to explicitly
implement that functionality. Thus, it stands as an abstraction layer that must be extended and
implemented by the corresponding sub-classes.
Interface: An interface is a classlike construct that contains only constants and abstract methods. An
interface is similar to an abstract class, but the intent of an interface is to specify behavior for objects .
Definition: public interface InterfaceName{ constant declarations; method signitures;}
All methods in an interface are implicitly abstract. On the other hand, an abstract class
may contain both abstract and non-abstract methods.
A class may implement a number of Interfaces, but can extend only one abstract class.
In order for a class to implement an interface, it must implement all its declared
methods. However, a class may not implement all declared methods of an abstract class.
Though, in this case, the sub-class must also be declared as abstract.
Abstract classes can implement interfaces without even providing the implementation
of interface methods.
Variables declared in a Java interface is by default final. An abstract class may contain
non-final variables.
Members of a Java interface are public by default. A member of an abstract class can
either be private, protected or public.