Sie sind auf Seite 1von 2

Advertise Us | Ask Question | forum | login|

Basics of Java
OOPs Concepts
Advantage of OOPs
Naming Convention
Object and Class
Method Overloading
Constructor
static variable,method
and block
this keyword
Inheritance(IS-A)
Aggregation(HAS-A)
Method Overriding
Covariant Return Type
super keyword
Instance Initializer
block
final keyword
Abstract class
Interface
Runtime Polymorphism
static and Dynamic
binding
Downcasting with
instanceof operator
Package
Access Modifiers
Encapsulation
Object class
Object Cloning
Java Array
Call By Value
strictfp keyword
API Document
Command Line
Argument
String Handling
Exception Handling
Nested Classes
Multithreading
Synchronization
I/O
Serialization
Networking
AWT
Event Handling
Swing
LayoutManager
Applet
Reflection API
Collection
JDBC
Java New Features
RMI
Internationalization
next>> << prev
<< prev next>>
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. Let's take a simple example:
Note: If you are beginner to java, skip this topic and return to it after OOPs concepts.
Simple example of Covariant Return Type
1. class A{
2. A get(){return this;}
3. }
4.
5. class B extends A{
6. B get(){return this;}
7. void message(){System.out.println("welcome to covariant return type");}
8.
9. public static void main(String args[]){
10. new B().get().message();
11. }
12. }
Output:welcome to covariant return type
As you can see in the above example, the return type of the get() method of A class is A but the return
type of the get() method of B class is B. Both methods have different return type but it is method overriding.
This is known as covariant return type.

Tweet Tweet 89 Like 11k 0

New: JAXB | Junit
Home Core Java Servlet JSP Struts2 Mail API Hibernate Spring Android Quiz Projects Interview Q Comment Forum
428 21
3
Google +
6
converted by Web2PDFConvert.com
Like the www.javatpoint.com on facebook / google+ / twitter / subscribe to get latest updates
Sitemap Core Java Servlet JSP Struts2 Hibernate Spring Android Interview Questions
javatpoint.com is developed to provide easy and point to point learning and training in detail. Examples might be simplified to improve reading and
basic understanding. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. If there is any
mistake, please mail to sonoojaiswal1987@gmail.com or sonoojaiswal@javatpoint.com. We provide assurance of 90% interview questions.
While using this site, you agree to have read and accepted our terms of use and privacy policy.
2011-2013 Javatpoint. All Rights Reserved.
javatpoint.com
Like
11,703 people like javatpoint.com.
Facebook social plugin
converted by Web2PDFConvert.com

Das könnte Ihnen auch gefallen