OOP IN JAVA ( METHOD OVERLOADING : STATIC AND INHERITANCE)

 STATIC

In Java, we must first build an instance of the class before can access it. On the other hand, there may be circumstances where want to access class without setting up any variables. In some circumstances,

Java's "static" keyword can be used. Class must be declared static if we wish to access them without generating a class instance. and also static isn't a  Access Modifier.

But it is used as a modifier and can directly access main method to if it is of static type. If the variable or method we create inside the class is kept with the static modifier, we can use the variable or method anywhere in the class. 

EX :-               

package com.dataflair.statickeyword;
public class StaticBlock
{
static String sentence;
static int number;
static
{
sentence = "Welcome to DataFlair";
number = 69;
}
public static void main(String args[])
{
System.out.println(sentence);
System.out.println("Value of Integer: "+number);


INHERITANCE



Its very important part of the OOP. Inheritance in Java is the method to create a hierarchy between classes by inheriting from other classes.

 Java Inheritance is transitive , for the basic example is BMW , so if BMW extends Car and Car extends Vehicle, then BMW Modern is also inherited from the Vehicle class. The first BMW Vehicle becomes the superclass and BMW Modern vehicle becomes the subclass. 

Points used in Inheritance

  • Class: A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
  • Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class.
  • Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.

The extends keyword is used to perform inheritance in Java. For example,


EX:-
class A{
string Color;
string name;
string light;
void drive(){
}
void break(){
}

class B extend A{
string camera;
string wi-fi;
void flying(){
}
Thank you.

Comments

Popular posts from this blog

DEMYSTIFYING THE POWER OF x86 ARCHITECTURE

A GUID TO BEACOMING A SOFTWARE ENGINEER

JAVA LAMBDA EXPRESSION