Results 1 to 2 of 2
  1. #1
    coder is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Question covariant return types

    hi,I am new to java...
    I couldn't learn about covariant return types in java..
    who can explain me...
    my other question is

    class A{
    public A go(){
    return new A();
    }
    public static void main(String args[]){
    A n=new A();
    n.go();//what will occur,I dont know how metod works with class
    //name,plz help

    }
    }

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Please use CODE tags when posting code.

    Quote Originally Posted by coder View Post
    I couldn't learn about covariant return types in java..
    who can explain me...
    This article (first Google hit for "Java covariant return types") explains it pretty well. Tell us what you don't understand about it.

    Java Tips - Covariant return types

    Quote Originally Posted by coder View Post
    my other question is
    Java Code:
    class A{
    
            public A go(){
                    return new A();
            }
    
            public static void main(String args[]) {
                    A n =new A();
                    n.go(); //what will occur,I dont know how metod works with class 
                              //name,plz help
            }
    }
    Essentially nothing will happen. You are creating one new object of type A, then calling its go() method, which creates another new object of type A. But you are not doing anything with the second one, and not even assigning it to a variable. Objects of type A have no local storage, or any other significant side effects, so basically nothing happens.

    -Gary-

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  2. Help with sorting two types:
    By twcast in forum New To Java
    Replies: 2
    Last Post: 02-11-2010, 04:37 PM
  3. Java Native Access (JNA) return types of void *
    By burnumd in forum Advanced Java
    Replies: 5
    Last Post: 01-15-2010, 12:09 AM
  4. generic types
    By jon80 in forum New To Java
    Replies: 6
    Last Post: 06-12-2009, 10:29 PM
  5. Collection Types
    By DavidG24 in forum New To Java
    Replies: 2
    Last Post: 04-18-2009, 05:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •