Which type of class is not instantiated?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Which type of class is not instantiated?

 
0
  #1
Apr 25th, 2005
This is kind of a weird senario. This question was at the java state championship I was at a few weeks ago. Here was the question:

Which type of class cannot be instantiated:

abstract
static
(choices I can't remember..they were wrong)

Would both abstract and static be correct answers? I've never heard of static classes, but if there is such a thing, wouldn't it be the Dot operator that calls it, and not an instantiation?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Which type of class is not instantiated?

 
0
  #2
Apr 25th, 2005
>Would both abstract and static be correct answers?
No, abstract is the correct answer. static only means that a nested class doesn't designate an inner class.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Which type of class is not instantiated?

 
0
  #3
Apr 25th, 2005
Originally Posted by Narue
>Would both abstract and static be correct answers?
No, abstract is the correct answer. static only means that a nested class doesn't designate an inner class.
OHHH, ok. I see, the actually main class of the static nested class would also have to be static, which isn't possible. In that case, you would be instantiating a class to get to the static..Correct?

Thanks for the reply by the way.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Which type of class is not instantiated?

 
0
  #4
Apr 25th, 2005
>In that case, you would be instantiating a class to get to the static
Huh? No, not at all. The following is legal:
  1. class Outer {
  2. static class Nested {}
  3. }
  4.  
  5. class Test {
  6. Outer.Nested obj = new Outer.Nested();
  7. }
But this is not:
  1. class Outer {
  2. class Nested {}
  3. }
  4.  
  5. class Test {
  6. Outer.Nested obj = new Outer.Nested();
  7. }
The difference is that a static class is somewhat like a static data member. An instance isn't required to access it.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Which type of class is not instantiated?

 
0
  #5
Apr 25th, 2005
Well how come you couldn't consider that an answer?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Which type of class is not instantiated?

 
0
  #6
Apr 25th, 2005
>Well how come you couldn't consider that an answer?
Because your explanation was so convoluted I didn't understand it, but it didn't smell right.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Which type of class is not instantiated?

 
0
  #7
Apr 26th, 2005
I was thinking since you have to call the outer class that you couldn't count it as the answer...Is this what you were meaning?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Which type of class is not instantiated?

 
0
  #8
Apr 26th, 2005
You can create instances of a static inner class, but not of an abstract class.

When you have a static inner class the Class instance for the inner class is static, but that has nothing to do with any instances of the inner class itself.

Consider an inner class to be a data member of the outer class.
In case of non-static inner classes you'll get a Class instance for the inner class for each instance of the outer class.
When you have a static inner class you'll get a single static Class instance at Class level for the outer class, therefore accessible without an instance of the outer class itself (enabling you to do new A.B() instead of new A().new B() for example).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Which type of class is not instantiated?

 
0
  #9
Apr 26th, 2005
Ahh I get it now. Thanks for the clarification jwenting.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC