944,128 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5073
  • Java RSS
Apr 25th, 2005
0

Which type of class is not instantiated?

Expand Post »
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?
Similar Threads
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 25th, 2005
0

Re: Which type of class is not instantiated?

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 25th, 2005
0

Re: Which type of class is not instantiated?

Quote 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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 25th, 2005
0

Re: Which type of class is not instantiated?

>In that case, you would be instantiating a class to get to the static
Huh? No, not at all. The following is legal:
Java Syntax (Toggle Plain Text)
  1. class Outer {
  2. static class Nested {}
  3. }
  4.  
  5. class Test {
  6. Outer.Nested obj = new Outer.Nested();
  7. }
But this is not:
Java Syntax (Toggle Plain Text)
  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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 25th, 2005
0

Re: Which type of class is not instantiated?

Well how come you couldn't consider that an answer?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 25th, 2005
0

Re: Which type of class is not instantiated?

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 26th, 2005
0

Re: Which type of class is not instantiated?

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?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 26th, 2005
0

Re: Which type of class is not instantiated?

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 26th, 2005
0

Re: Which type of class is not instantiated?

Ahh I get it now. Thanks for the clarification jwenting.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: parsing error (XML file-java-schema)
Next Thread in Java Forum Timeline: Please Help Me





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC