PackageAbstractclassandinterface; Public classAbstractclasstest { Public Static voidMain (string[] args) {AbstractClass1 AbstractClass=NewAbstractClass1 () {@Overrideprotected voidSetprotectedmethod () {System.out.println ("Calling Method: Setprotectedmethod"); } @Override Public voidSetpublicmethod () {//TODO auto-generated Method Stub} @OverridevoidSetnomethod () {//TODO auto-generated Method Stub } }; Abstractclass.setprotectedmethod (); System.out.println ("Successful Execution"); }} Abstract classabstractclass1{PrivateString a= "Private"; PublicString b= "Public"; protectedString c= "protected"; String D= "NULL"; FinalString e= "Final"; StaticString f= "Static"; //method problems for abstract classes//abstract methods cannot be implemented Public Abstract voidSetpublicmethod (); //If you are private, you cannot inherit from the quilt class and the subclass cannot implement the method//private abstract void Setprivatemethod (); //protected can be modified protected Abstract voidSetprotectedmethod (); //Public By default Abstract voidSetnomethod (); //You can also use a non-abstract method Public voidSetnotabstractmethod () {}}
More than one class in a file, the public class is consistent with the Main method