Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

@override java example

// A Simple Java program to demonstrate
// Overriding and Access-Modifiers
  
class Parent {
    // private methods are not overridden
    private void m1()
    {
        System.out.println("From parent m1()");
    }
  
    protected void m2()
    {
        System.out.println("From parent m2()");
    }
}
  
class Child extends Parent {
    // new m1() method
    // unique to Child class
    private void m1()
    {
        System.out.println("From child m1()");
    }
  
    // overriding method
    // with more accessibility
    @Override
    public void m2()
    {
        System.out.println("From child m2()");
    }
}
  
// Driver class
class Main {
    public static void main(String[] args)
    {
        Parent obj1 = new Parent();
        obj1.m2();
        Parent obj2 = new Child();
        obj2.m2();
    }
}
Comment

@override java example

// A Simple Java program to demonstrate
// Overriding and Access-Modifiers
  
class Parent {
    // private methods are not overridden
    private void m1()
    {
        System.out.println("From parent m1()");
    }
  
    protected void m2()
    {
        System.out.println("From parent m2()");
    }
}
  
class Child extends Parent {
    // new m1() method
    // unique to Child class
    private void m1()
    {
        System.out.println("From child m1()");
    }
  
    // overriding method
    // with more accessibility
    @Override
    public void m2()
    {
        System.out.println("From child m2()");
    }
}
  
// Driver class
class Main {
    public static void main(String[] args)
    {
        Parent obj1 = new Parent();
        obj1.m2();
        Parent obj2 = new Child();
        obj2.m2();
    }
}
Comment

what is override in java?

// A Simple Java program to demonstrate
// method overriding in java
  
// Base Class
class Parent {
    void show()
    {
        System.out.println("Parent's show()");
    }
}
  
// Inherited class
class Child extends Parent {
    // This method overrides show() of Parent
    @Override
    void show()
    {
        System.out.println("Child's show()");
    }
}
  
// Driver class
class Main {
    public static void main(String[] args)
    {
        // If a Parent type reference refers
        // to a Parent object, then Parent's
        // show is called
        Parent obj1 = new Parent();
        obj1.show();
  
        // If a Parent type reference refers
        // to a Child object Child's show()
        // is called. This is called RUN TIME
        // POLYMORPHISM.
        Parent obj2 = new Child();
        obj2.show();
    }
}
Comment

Java @Override

@Override
Comment

PREVIOUS NEXT
Code Example
Java :: assert log in unit testing 
Java :: java first character string number 
Java :: cors spring 
Java :: spring boot param object 
Java :: how to get current time and date in android 
Java :: Java alt f4 
Java :: read wss endpoint java 
Java :: math.min java 
Java :: spring boot dockerfile 
Java :: uses or overrides a deprecated API. 
Java :: creating a menu in java 
Java :: design custom button in android 
Java :: view all certificates from keystore java 
Java :: set text from strings.xml 
Java :: Java printf() Method 
Java :: delet file from path android 
Java :: splay tree java implementation 
Java :: import android.support.v7.app.alertdialog androidx 
Java :: implement stack using linked list java 
Java :: Java User Input (Scanner) 
Java :: Loop in singly linked list 
Java :: set matrix zeros programming creek 
Java :: mockito method called 
Java :: converting string to int in java 
Java :: android java how to blur an image 
Java :: java create arraylist with size 
Java :: Simple While Loop Java Example 
Java :: android foreground services set auto cancel not working 
Java :: java opp 
Java :: array reverse in java 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =