Escolar Documentos
Profissional Documentos
Cultura Documentos
• Java Modifiers
• Abstract Classes
• Interface
• Inner Class
• Classes Inside a Method
• Anonymous Inner Classes
Java Modifiers
Access Modifiers
• public
• private
• protected
Other Modifiers
• static
• final
Access Modifiers
public
- class, attributes and methods which
have been declared as public can be
accessed/used by any class without
restriction
private
-can only be applied to attributes and
methods and access to them is
restricted to the class where they are
defined
Access Modifiers
protected
-can only be applied to attributes and methods
- access to the attributes and methods are
allowed for subclasses and other classes in the
same package
“default “ or friendly
-if no access modifier is specified, the modifier is
assumed to be friendly
- can be applied to class, attributes and methods
and access to them is allowed for classes
within the same package only
Static Modifier
- can be applied to attributes, methods,
code blocks and inner classes
static variables or data members
- referred to as class members
- shared by all objects of the class
- can be accessed without creating an
object
Static Modifier
static method
- referred to as class methods
- methods that refer to static members
or methods that do not refer to any
particular object
- no this pointer
- can be invoked without creating an
object of a class
Static Modifier
static initializer
- static code block that is executed only
once when the class is loaded
- normally used to initialize static
variables
final Modifier
- can be applied to classes, variables,
methods
- final class can not be subclassed
- a final method can not be overridden
- a final variable is a constant
Abstract Class
- As you move up to the inheritance hierarchy, classes become
more general and probably more abstract
Vehicle
Sedan Wagon
- Interface defines :
a. “classes” with pure abstract methods and no attribute
definitions.
b. Methods that every interface implementation must implemen
C. no actual implementation of methods.
Or :
- A static inner class behaves just like a top level class with
modified naming scheme.
Classes Inside a Method