Top LEVEL
must be at least one public top level classesshit i did not know we can have multiple top level classes!! wow, new stuff after a zillion years of java
Top level - public, abstract, final yeah yeah
not private duh, nor protected nor static
More than one top-level class can be defined in a Java source file, but there can be at most one public top-level class declaration. The file name must match the name of the public class. The file name can be anything, provided there is not a public class definition. If there is more than one class declaration in a source file, each will be compiled into separate .class files. The following example has more than one source file. It must be divided into separate source files that have at most one public class declaration. The compiler will complain if there are two public classes at the same file.
//Inner class examples with //Class Modifiers //A top level class public class Point {} abstract class Point {} final class Point {} class Point {} //Some variations public final class Point{} public abstract class Point{} //Error conditions public public class Point{}//ERROR! private class Point{}//ERROR! protected class Point{}//ERROR! |
AbStRaCt Classes
love the colors!!
An abstract class is a class which may have incomplete implementations for its methods, some of the methods can have implementation and some others can be empty method declarations. If an abstract class is going to be subclassed, all of its incomplete method implementations must be implemented in the subclass, or the subclass must be declared as abstract too; otherwise the compiler will complain.
// An abstract class abstract class Shape { int x,y; abstract void draw(); void setX(int _x){ x=_x; } void setY(int _y){ y=_y; }} |
you can make abstract classes fromn abstract classes
Interface ezeesez
An interface is the same as an abstract class, but you cannot define any method implementations at all. Abstract classes allow having some method implementations. Method implementations cannot be defined when an interface is concerned. Interfaces are defined with the interface keyword. An interface doesn't need abstract and class keywords. Member variables are implicitly defined as public static final. An abstract class can have a constructor(s), but the constructor(s) must be implemented. An Interface must not have a constructor at all.
public interface class Shape { // note that abstract // is not used in here void draw() ; } |
No comments:
Post a Comment