Java-Example of Protected Access

Example of Protected Access When the protected access control modifier is specified for a variable or method in a class, it can be accessed by the methods of the same class, subclasses in the same package and non-subclasses in the same package. Furthermore, protected variables and methods can be accessed by all methods of subclasses … Read more…

Java-Access Modifiers

Access Modifiers We can define the scope of a variable or method or class by using the access modifiers. The scope of an entity is the region in which it is accessible. Java has the following four levels of controlling access to variables, methods and classes. 1. Private Access Variables are generally declared with the … Read more…

Java-Creating Subclasses

Creating Subclasses It is also possible to subclass a class that has been imported from another package. This is illustrated by following program. Note that the Data class inside the mypack package. Program Package Source package mypack; public class Data { public int data1 = 20; public void printData() { System.out.println(“data1 = “+data1); } } … Read more…

Java-Lang Package

Lang Package All classes from the java.lang package are automatically imported into every Java program. Following program used the System and String classes. Both of these classes belong to the java.lang package. As this package would be automatically imported, we did not import it ourselves in that program. Program Program Source public class Javaapp { public … Read more…

Java-API Packages

API Packages Java APl(Application Program Interface) provides a large numbers of classes grouped into different packages according to functionality. Most of the time we use the packages available with the the Java API. Following figure shows the system packages that are frequently used in the programs. Java System Packages and Their Classes java.lang Language support … Read more…