Skip to main content

Posts

  Inheritance Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another(parent). It is an important part of OOP. The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class). extends  is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword. Syntax class Super {    ..... .... } class Sub extends Super {    .....    ..... } Types of Inheritance Java supports the following four types of inheritance: ○        Single Inheritance ○        Multi-level Inheritance ○        Hierarchical Inheritance ○        Hybrid Inheritance Single Inheritance In single inheritance, a sub-class is derived from only o...
Recent posts

Unit 3 Java

Java Methods A method in Java is a block of code that performs a specific task and executes only when it is called (invoked) . It helps in reusing code by defining a logic once and calling it multiple times whenever required. Methods are also known as functions in other programming languages such as C or C++.   Purpose of Methods The main goals of using methods in Java are: Perform specific tasks: Each method handles one defined operation, like calculation or displaying data. Avoid code repetition: The same logic can be reused by calling the method instead of rewriting it. Make programs modular and readable: Dividing a program into smaller methods makes it easier to understand and debug. Improve code reusability: Once defined, a method can be used in different parts of the program or other classes.   Types of Methods in Java There are two main types of methods: 1.       Predefined Methods (Built-in Methods) 2. ...