Java Classes

Java Classes

Previous Home Next

 

Java uses different type of classes top level class or super class,nested classes(class within a class) called sub class,member classes ,local classes ,anonymous classes ,abstract classes ,final classes etc.

Java Classes
          o Class Syntax
          o The Point Class
          o Class Modifiers
          o Extending Super classes
          o Adding Body to Classes
Super class or top level class:-the top level class that is do not nested class

Sub classes:-. A class is said to be a direct subclass of the class it extends.

A nested class :-
is any class whose declaration occurs within the body of another class or interface.

CLASS MODIFIERS

An abstract class :-
is a class that is incomplete, or to be considered incomplete. Normal classes may have abstract methods that is methods that are declared but not yet implemented, only if they are abstract classes.
 If a normal class that is not abstract contains an abstract method, then a compile-time error occurs.

A class can be declared final:-
if its definition is complete and no subclasses are desired or required.
 A compile-time error occurs if the name of a final class appears in the extends of another class declaration; this implies that a final class cannot have any subclasses.

Public class:-
this class is accessible any where from the class or outside the class.

Static class:- make an inner class a top level class.

Strictfp class:-All the methods in the class are implicitly strictfp.The effect of the strictfp modifier is to make all float or double expressions within the class declaration be explicitly FP-strict


 Class point in java:-

public class Point
extends Point2D
implements Serializable

A point representing a location in (x, y) coordinate space, specified in integer precision.

A class declaration may include class modifiers.

      ClassModifiers:
          ClassModifier
          ClassModifiers ClassModifier

      ClassModifier: one of
          public protected private
          abstract static final strictfp

Class body declaration

ClassBody:
    { ClassBodyDeclarationsopt }

ClassBodyDeclarations:
    ClassBodyDeclaration
    ClassBodyDeclarations ClassBodyDeclaration

ClassBodyDeclaration:
    ClassMemberDeclaration
    InstanceInitializer
    StaticInitializer
    ConstructorDeclaration



 Super and sub class
class Point // super class is defined as point
{
int x, y;
}
final class ColoredPoint extends Point // sub class ColorPoint extends super Class
// point using extend keyword
{
int color;
}

Abstract class
public abstract class GraphicObject 
{

// declare fields
// declare non-abstract methods
abstract void draw();
}

Final class

final class A // final class declaration all its methods are final
{
private int type;
public int getType()
{
return type;
}
}

public class test // sub class




Previous Home Next