Skip to main content

Posts

Showing posts from January, 2022

Packages In Java

  Package in java is a group of similar type of classes, interface and sub-package. Packages in java can be defined in two ways which are 1 Built-in Packages 2 User-defined Packages Built-in Packages are       * Lang      * Util      * io      * awt      * net      * applet, etc. User-defined packages can be anything which are created by the user. Packages are nothing but container of the classes which store the no of classes, interface and their methods. Advantages of Packages 1 It provide access Protection 2 It removes the naming collision 3 it is used to categorize the classes and interface so that they can be easily maintained. Steps for creating a package Step-1 Create a folder in any drive of your choice  Step-2 example in d: package1 (it is the name of the package) Step-3 Open the java application and type the following code package package1; public class demo {  public void display() { System.out.println("Welcome to Programmingssidepoint"); } } Step-4 Sa

Interface In Java

 An Interface  in java programming language is exact copy of a class. It consist of abstract methods and static constants.  Interface is a method which is used to achieve abstraction. It contains abstract methods not the method body. It is used to achieve abstraction and multiple inheritance in java. It represents the IS-A relationship.   Reasons why to use Inheritance in java? 1) It is used to achieve abstraction. 2) By interface, we can support the functionality of multiple inheritance. 3) It can be used to achieve loose coupling.( loose coupling in java means that the classes are independent of each other. The only knowledge one class has about the other class is what the other class has exposed through its interface in loose coupling.). Declaration of an Interface in Java Interface in java is declared using the keyword that is interface keyword.  It provides that total abstraction, that means all methods in the interface are declared with empty body and all the fields are public, s

Inheritance In Java

  Inheritance Inheritance is a process or a mechanism where one class acquire the properties which include methods and fields of another class. With the use of this concept the information is made manageable in a hierarchical order. The class which inherits the properties of another class is known as subclass  or derived class or child class . and the class whose properties are inherited is called as base class or parent class . In java inheritance cannot be achieved until we use extends keyword. Reason to use Inheritance 1 For Method overriding 2 For code reusability  Syntax: class abc { ......... ......... } class xyz extends abc { ......... ......... } ---------------------------------------------------------------------------------------------------------------------------- Example //WAP to Demonstrate Inheritance............. import java.io.*; class Superclass { BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); Double num1,num2; void get() { try