Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1876 > unrolled thread
| Started by | Davej <galt_57@hotmail.com> |
|---|---|
| First post | 2012-06-17 06:44 -0700 |
| Last post | 2012-06-19 09:18 -0700 |
| Articles | 13 — 8 participants |
Back to article view | Back to comp.lang.java.help
A a = new B(); Davej <galt_57@hotmail.com> - 2012-06-17 06:44 -0700
Re: A a = new B(); markspace <-@.> - 2012-06-17 07:55 -0700
Re: A a = new B(); Davej <galt_57@hotmail.com> - 2012-06-17 09:23 -0700
Re: A a = new B(); David Lamb <dalamb@cs.queensu.ca> - 2012-06-17 12:56 -0400
Re: A a = new B(); markspace <-@.> - 2012-06-17 10:02 -0700
Re: A a = new B(); rossum <rossum48@coldmail.com> - 2012-06-17 18:00 +0100
Re: A a = new B(); markspace <-@.> - 2012-06-17 11:03 -0700
Re: A a = new B(); Roedy Green <see_website@mindprod.com.invalid> - 2012-06-17 14:02 -0700
Re: A a = new B(); Joerg Meier <joergmmeier@arcor.de> - 2012-06-19 02:31 +0200
Re: A a = new B(); Lew <noone@lewscanon.com> - 2012-06-18 22:12 -0700
Re: A a = new B(); Roedy Green <see_website@mindprod.com.invalid> - 2012-06-19 04:57 -0700
Re: A a = new B(); Joerg Meier <joergmmeier@arcor.de> - 2012-06-19 14:49 +0200
Re: A a = new B(); Gene Wirchenko <genew@ocis.net> - 2012-06-19 09:18 -0700
| From | Davej <galt_57@hotmail.com> |
|---|---|
| Date | 2012-06-17 06:44 -0700 |
| Subject | A a = new B(); |
| Message-ID | <c66c076a-3019-43dd-9d44-43ea504884f4@v33g2000yqv.googlegroups.com> |
Can this be valid? If so what is this called? Thanks.
[toc] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-06-17 07:55 -0700 |
| Message-ID | <jrkr61$vv2$1@dont-email.me> |
| In reply to | #1876 |
On 6/17/2012 6:44 AM, Davej wrote: > Can this be valid? If so what is this called? Thanks. > I'm pretty sure this is a "do your own homework" sort of deal.
[toc] | [prev] | [next] | [standalone]
| From | Davej <galt_57@hotmail.com> |
|---|---|
| Date | 2012-06-17 09:23 -0700 |
| Message-ID | <5e21b660-5909-41a3-aff1-b2d59a42bad2@m8g2000yqo.googlegroups.com> |
| In reply to | #1877 |
On Jun 17, 9:55 am, markspace <-@.> wrote: > On 6/17/2012 6:44 AM, Davej wrote: > > > Can this be valid? If so what is this called? Thanks. > > I'm pretty sure this is a "do your own homework" sort of deal. It's not my homework, but I've never seen this before, so I don't even know what to look up.
[toc] | [prev] | [next] | [standalone]
| From | David Lamb <dalamb@cs.queensu.ca> |
|---|---|
| Date | 2012-06-17 12:56 -0400 |
| Message-ID | <jrl28a$bk2$1@dont-email.me> |
| In reply to | #1878 |
On 17/06/2012 12:23 PM, Davej wrote: > On Jun 17, 9:55 am, markspace<-@.> wrote: >> On 6/17/2012 6:44 AM, Davej wrote: >> >>> Can this be valid? If so what is this called? Thanks. >> >> I'm pretty sure this is a "do your own homework" sort of deal. > > It's not my homework, but I've never seen this before, so I don't even > know what to look up. Look up "inheritance". Sorry to be cryptic, but markspace is right that this does look like a lot of "help me cheat on my homework" questions we've seen over the years.
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-06-17 10:02 -0700 |
| Message-ID | <jrl2jr$f1g$1@dont-email.me> |
| In reply to | #1878 |
On 6/17/2012 9:23 AM, Davej wrote: > On Jun 17, 9:55 am, markspace <-@.> wrote: >> On 6/17/2012 6:44 AM, Davej wrote: >> >>> Can this be valid? If so what is this called? Thanks. >> >> I'm pretty sure this is a "do your own homework" sort of deal. > > It's not my homework, but I've never seen this before, so I don't even > know what to look up. > Yeah, I don't mean to be rude, but it really does look like a student question. One you should be asking your instructor. If you've never seen it before, where do you see it now? I'd like some context before I give you any further pointers. If there's a blog or some source code online, a link would be preferable. Also, this question is hugely remedial. What is your experience with programming?
[toc] | [prev] | [next] | [standalone]
| From | rossum <rossum48@coldmail.com> |
|---|---|
| Date | 2012-06-17 18:00 +0100 |
| Message-ID | <n73st7t63ijcgo7je5q12pbsleorv12nvq@4ax.com> |
| In reply to | #1876 |
On Sun, 17 Jun 2012 06:44:50 -0700 (PDT), Davej <galt_57@hotmail.com> wrote: >Can this be valid? If so what is this called? Thanks. What is the relationship between class A and class B? rossum
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-06-17 11:03 -0700 |
| Message-ID | <jrl66i$5nn$1@dont-email.me> |
| In reply to | #1880 |
On 6/17/2012 10:00 AM, rossum wrote: > On Sun, 17 Jun 2012 06:44:50 -0700 (PDT), Davej <galt_57@hotmail.com> > wrote: > >> Can this be valid? If so what is this called? Thanks. > What is the relationship between class A and class B? Don't forget that the first part of his question is "is this valid?" What if it isn't valid? What if the code snipette doesn't compile? Is there a case where it would not be correct? The fact the the question and the example are *so* well chosen to sit on a knife edge of various presumptions makes the question look like homework. It's too smart to be a dumb question.
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-06-17 14:02 -0700 |
| Message-ID | <oahst75bbaflea78c3t08f7jf23b8bns83@4ax.com> |
| In reply to | #1876 |
On Sun, 17 Jun 2012 06:44:50 -0700 (PDT), Davej <galt_57@hotmail.com> wrote, quoted or indirectly quoted someone who said : >Can this be valid? If so what is this called? Thanks. what are A and B. A might be an interface and B a class. A might be a superclass or subclass of B. Newbies tend to write code of the form A a = new A(); Old hands tend to write code of the form SomeInterface a = new ConcreteClass(); -- Roedy Green Canadian Mind Products http://mindprod.com If you look in a computer programmer's freezer you will find all kinds of containers, but none of them labeled. They do the same thing creating files without labeling the encoding. You are just supposed to know. Ditto with the MIME type, the separator and comment delimiters and column names in CSV files. Ditto with the endian convention. Imagine how much more civilised life would have been if Martha Stewart were the first programmer.
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2012-06-19 02:31 +0200 |
| Message-ID | <su5q92l5zfxi$.1ihbzriyuwtwy$.dlg@40tude.net> |
| In reply to | #1883 |
On Sun, 17 Jun 2012 14:02:03 -0700, Roedy Green wrote: > On Sun, 17 Jun 2012 06:44:50 -0700 (PDT), Davej <galt_57@hotmail.com> > wrote, quoted or indirectly quoted someone who said : >>Can this be valid? If so what is this called? Thanks. > what are A and B. A might be an interface and B a class. A might be > a superclass or subclass of B. I don't see how A could be a subclass of B. What would happen if you called a.x(); where x() is a method only subclass A has ? String a = new Object(); // <- This will not compile, even though String is a subclass of Object Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-06-18 22:12 -0700 |
| Message-ID | <jrp1o3$dkm$1@news.albasani.net> |
| In reply to | #1885 |
Joerg Meier wrote: > Roedy Green wrote: >> Davej wrote, quoted or indirectly quoted someone who said : >>> Can this be valid? If so what is this called? Thanks. >> what are A and B. A might be an interface and B a class. A might be >> a superclass or subclass of B. > > I don't see how A could be a subclass of B. What would happen if you called > a.x(); where x() is a method only subclass A has ? > > String a = new Object(); //<- This will not compile, even though String is > a subclass of Object That is an excellent question and observation. As the OP originally posted it, switch for this example to: import java.util.ArrayList; import javax.management.relation.RoleList; Downcasting from the general type (ArrayList) to the specific (RoleList): RoleList specifics = new ArrayList<Object>(); the code won't compile for the reasons you state - the compiler cannot know that the new instance will fit into the subtype reference. You overcome the compiler's objections with a cast: RoleList specifics = (RoleList) new ArrayList<Object>(); This will get you past the compiler but blow up at runtime. Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to javax.management.relation.RoleList at eegee.Casterol.run(Casterol.java:25) at eegee.Casterol.main(Casterol.java:35) Upcasting always works, of course, without special ops. ArrayList<Object> generals = new RoleList(); List<Object> potus = new RoleList(); In fact, upcasting like that is rather the point. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-06-19 04:57 -0700 |
| Message-ID | <58q0u71hbr3vlod0kgm63mcrrc3av6qn4e@4ax.com> |
| In reply to | #1885 |
On Tue, 19 Jun 2012 02:31:09 +0200, Joerg Meier <joergmmeier@arcor.de> wrote, quoted or indirectly quoted someone who said : >>>Can this be valid? If so what is this called? Thanks. >> what are A and B. A might be an interface and B a class. A might be >> a superclass or subclass of B. > >I don't see how A could be a subclass of B. What would happen if you called >a.x(); where x() is a method only subclass A has ? > >String a = new Object(); // <- This will not compile, even though String is >a subclass of Object I was enumerating the possibilities you might consider. I was not claiming they were all valid syntax. I did not want to give the answer away too easily. -- Roedy Green Canadian Mind Products http://mindprod.com If you look in a computer programmer's freezer you will find all kinds of containers, but none of them labeled. They do the same thing creating files without labeling the encoding. You are just supposed to know. Ditto with the MIME type, the separator and comment delimiters and column names in CSV files. Ditto with the endian convention. Imagine how much more civilised life would have been if Martha Stewart were the first programmer.
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2012-06-19 14:49 +0200 |
| Message-ID | <39gkw323aa17$.wkrhvcckp72o$.dlg@40tude.net> |
| In reply to | #1888 |
On Tue, 19 Jun 2012 04:57:50 -0700, Roedy Green wrote: > On Tue, 19 Jun 2012 02:31:09 +0200, Joerg Meier <joergmmeier@arcor.de> > wrote, quoted or indirectly quoted someone who said : > >>>>Can this be valid? If so what is this called? Thanks. >>> what are A and B. A might be an interface and B a class. A might be >>> a superclass or subclass of B. >>I don't see how A could be a subclass of B. What would happen if you called >>a.x(); where x() is a method only subclass A has ? >>String a = new Object(); // <- This will not compile, even though String is >>a subclass of Object > I was enumerating the possibilities you might consider. I was not > claiming they were all valid syntax. I did not want to give the > answer away too easily. Why would you state something you know is impossible as a possibility ? That would only serve to confused newbies. And if you were to enumerating the possibilities whether legit or not, why not list A and B both being interfaces ? Why not A being a class and B being and interface ? Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2012-06-19 09:18 -0700 |
| Message-ID | <df91u7ld4q27qp0ndolvc5c44c72k77gdu@4ax.com> |
| In reply to | #1889 |
On Tue, 19 Jun 2012 14:49:31 +0200, Joerg Meier <joergmmeier@arcor.de>
wrote:
[snip]
>Why would you state something you know is impossible as a possibility ?
>That would only serve to confused newbies. And if you were to enumerating
The original question has the smell of being a homework problem.
Helping with homework: maybe; doing it for him: no.
[snip]
Sincerely,
Gene Wirchenko
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.help
csiph-web