TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Sunday, 12 April 2020

Covariant Return Type In Java | Covariant Return Type In Java Example

          Covariant Return Type

The covariant return type specifies that the return type may vary in the same direction as the subclass.
Before Java5, it was not possible to override any method by changing the return type. But now, since Java5, it is possible to override method by changing the return type if subclass overrides any method whose return type is Non-Primitive but it changes its return type to subclass type. 


Example of covariant return in java


Fig: Covariant Type In Java 

Example of Covariant Return Type

      class A{  
      A get(){return this;}    
      class B1 extends A{  
      B1 get(){return this;}  
     void message(){System.out.println("welcome to covariant return type");}  
      public static void main(String args[]){  
      new B1().get().message();  
       }  
}  

Output:


welcome to covariant return type

No comments:

Post a Comment