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 :: how to make 2d array of strings in java 
Java :: Java if (if-then) Statement 
Java :: Java Filters 
Java :: finding min and max from given number in java 
Java :: how to sprint minecraft java 
Java :: java hello world program 
Java :: java division of 2 numbers with decimal places 
Java :: @runwith junit 5 
Java :: how to create a derived class in Java 
Java :: what to do in minecraft 
Java :: print outputstream to console java 
Java :: save text in edditext java 
Java :: android MediaStore update cache before query 
Java :: java scanner tokens with withespace 
Sql :: PROSYS SQL BKP 
Sql :: postgres active connections 
Sql :: psql drop column 
Sql :: forgot mysql root password stackoverflow 
Sql :: uninstall mysql on ubuntu 
Sql :: oracle columns in all_tables 
Sql :: database url postgres 
Sql :: sql drop procedure if exists 
Sql :: show list of users in mysql 
Sql :: find string in stored procedure sql server 
Sql :: sql last row in table 
Sql :: oracle modify column type 
Sql :: postgres stop server mac 
Sql :: restart mysql server ubuntu 
Sql :: postgres restart id 
Sql :: how to get all table names in sql query 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =