?
Solved

User Defined Data Types

Posted on 2003-03-06
8
Medium Priority
?
159 Views
Last Modified: 2010-03-31
Is there a way to created a user defined data type in Java WITHOUT inheriting it from a superclass? Something like a data struct in C OR a user defined type in VB?
0
Comment
Question by:freejaso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 8083577
No. Every object is a subclass of Object
0
 

Expert Comment

by:Lavendermpl
ID: 8086035
You may use the class to define your data structure.
in C:
typedef struct test {
   int a;
   char d;
};

in Java:
class test {
   int a;
   char d;
}
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8087322
What CEHJ has quoted is correct. Every class you create will automatically be a subclass of Object.

Mayank.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:doddjames
ID: 8087568

Interestingly, I wonder what the relationship between an interface and Object is...  You can't tell what the implementation class will extend until it's instantiated..

public interface Bar {
    Object foo = null;
    public Object bar = foo;
    public static final String FOOBAR = "wizz";
}

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8087602
>>WITHOUT inheriting it from a superclass?

Why would you want to do that btw?

>>You can't tell what the implementation class will extend until it's instantiated..

You can certainly tell that it'll be a subclass of Object ;-)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8087697
Dear doddjames,

The interface will not have anything to do with Object but when the interface is implemented by a class, that class will automatically be a subclass of Object. And without an implementing class, your interface is useless. Hope you got that.

Mayank.
0
 

Expert Comment

by:doddjames
ID: 8087955

Hi mayankeagle,

Your (vociferous) assertion is false.

I am perfectly capable of using an interface without implementing it with a class.
 
public interface Constants {
   public static final String MY_CONSTANT = "blah";
}

Constants.MY_CONSTANT is perfectly usable.  I don't agree with this style myself, but it is legal and certainly conflicts with your idea of an interface without an implementing object being 'useless'.

I too hope you "get" it. :-)
0
 

Author Comment

by:freejaso
ID: 8106288
Thanks for your comments.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question