?
Solved

variable's types

Posted on 2004-11-28
10
Medium Priority
?
247 Views
Last Modified: 2010-03-31
hi all,

I caught up with one prob relating to variables and its datatype..

for example,

int testInteger = 0;

int is the datatype
testInteger is the variable name
0 is the value

however, for

MyClass className = MyClass();

how is MyClass the datatype?
0
Comment
Question by:eturfclub
  • 6
  • 4
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12691972
that should be:

MyClass className = new MyClass();
0
 
LVL 92

Expert Comment

by:objects
ID: 12691980
MyClass is class that the variable className references an instance of
0
 

Author Comment

by:eturfclub
ID: 12691995
oh... so MyClass() is juz a dummy in this case juz to tell java that there's no constructor argument to be parsed into the class?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 92

Expert Comment

by:objects
ID: 12692009
Yes MyClass() says to call the classes default (no arguments) ctor.
0
 

Author Comment

by:eturfclub
ID: 12692035
how about interfaces??

interfaceOne variableName = new className();

how does this explain in this context? kindly advice.
0
 
LVL 92

Expert Comment

by:objects
ID: 12692120
variableName references an instance that implements interfaceOne.
In this case it references an instance of className
0
 

Author Comment

by:eturfclub
ID: 12692432
hmm.. meaning... mind to show me a little snipplet code ? thankx..
0
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 12692440
List l = new ArrayList();

the variable l has type List
But it references an instance of ArrayList (which implements List)
0
 

Author Comment

by:eturfclub
ID: 12692700
thanks..
0
 
LVL 92

Expert Comment

by:objects
ID: 12692732
no worries :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 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