Java Job Interview Questions - Quick Reference Points / Points to Remember
Declaration and Access Control - Quick Reference
Ø There can be only one public class per a source code file.
Ø The name of the source code file must be same as the public class in that file.
Ø A class file should first have a package name (if any) , then import statements (if any) and class declaration.
Ø A class can be marked either as public or with no access modifier, which specifies package (default) access.
Ø A class can be marked as strictfp, final or abstract.
Ø A class can not be declared as private or protected.
Ø A class cannot be marked as both abstract and final.
Ø A final class cannot be sub classed ( extended)
Ø An abstract class must be sub classed.
Ø An abstract class cannot be instantiated i.e it is not possible to create an object of an abstract class.
Ø Marking a class as final is to avoid overriding of its method in subclasses.
Ø An abstract class is used to define a generic behaviour of an object.
Ø If any method of a class is abstract, whole class must be marked as abstract.
Ø A class can be abstract even if there are no abstract methods.
Ø Abstract methods ends with a semicolon.
Ø Abstract classes let us to use polymorphism.
Ø Methods and instance variables of a class is collectively known as members of a class.
Ø Members of a class can have four different access levels – public, protected, default and
private.
Ø public – Access Anywhere
Ø protected – Access in the same package and in subclasses.
Ø default (no access modifier) – Access inside same package.
Ø private – Access inside same class.
Ø A member marked as private cannot be accessed outside the same class.
No comments:
Post a Comment