473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Paranthesis use

Well ! I have a confusion.When we length of an array we just use a.length; but to find length of an string we use S.length();.Why paranthesis are not used in case of array,however to call any method we use paranthesis?

I have a other problem too,i created an object of self defined class MyObject.Now how can i give the string behavior to the object i made,for e.g. the objects can be concated(concated because object should behave like string)?
Sep 12 '07 #1
4 1684
r035198x
13,262 8TB
Well ! I have a confusion.When we length of an array we just use a.length; but to find length of an string we use S.length();.Why paranthesis are not used in case of array,howvr to call any method we use paranthesis??
Expand|Select|Wrap|Line Numbers
  1. Class Why {
  2. static int aField = 0;
  3.         static int aMethod() {
  4.              return 0;
  5.         }
  6. }
You say Why.aField
and
Why.aMethod();
Sep 12 '07 #2
No!! take this as example:

class Why
{ int a[] ={1,5,8,3,0,6};
String S ="Why it happen";
int l_array,l_string;
l_array = a.length; // return 6
l_string = S.length(); // return 13
}

I mean Why a.length;
and
S.length();
Sep 12 '07 #3
r035198x
13,262 8TB
No!! take this as example:

class Why
{ int a[] ={1,5,8,3,0,6};
String S ="Why it happen";
int l_array,l_string;
l_array = a.length; // return 6
l_string = S.length(); // return 13
}

I mean Why a.length;
and
S.length();
But if you look at my example again, you would see why.
One is a field and the other is a method.
Sep 12 '07 #4
JosAH
11,448 Expert 8TB
No!! take this as example:

class Why
{ int a[] ={1,5,8,3,0,6};
String S ="Why it happen";
int l_array,l_string;
l_array = a.length; // return 6
l_string = S.length(); // return 13
}

I mean Why a.length;
and
S.length();
As r035198x already wrote: the length field for arrays is, well, a field, whille
the length() method for a String is a method. Arrays are a bit funny: they're all
objects and direct decendants of the Object class; they're all final (non-extendable)
as well and they don't have methods defined themselves (you can use Object's
methods on arrays though).

Arrays always have been a difficult thing when it comes to object oriented
programming. A 'Derived' may be a 'Base' but an array of 'Derived' isn't an
array of 'Base'; don't get me started on this ;-)

Just remember that arrays are a bit funny.

kind regards,

Jos
Sep 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Pavel Vetesnik | last post by:
Hello, my question is probably quite stupid, but I really don't know how to solve it. I have code like this: =============================================== <button title="Osobní nastavení...
10
by: Lakshmi Narayanan.R | last post by:
Hi Experts, Using keyword "To" in select case giving error.The following code is got from www.microsrosoft.com itself. What is the wrong with this?. <% Dim Number1 Number1 = 7 ' Initialize...
62
by: Kelvin Moss | last post by:
Hi all, Which is the recommended style in production code for the following - .... fp = fopen("xyz.txt", "r"); if (fp == NULL) { .... }
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
7
by: Zest4Csharp | last post by:
Can someone please show me where to find documentation about the use of paranthesis in the context shown in the sample line of code below:? Button bt=(Button)sender; Your help is truly...
16
by: Jm | last post by:
Hi All Is it possible to determine who is logged onto a machine from inside a service using code in vb.net ? I have found some code that seems to work under vb6, but doesnt under .NET ? Any help...
4
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
1
by: kuzen | last post by:
Hi guys, Could you plz check this code out and tell what the problem is. Thanks in advance CREATE TABLE RESERVATIONS ( RESERVATION_ID NUMBER(5), RENTER NUMBER(6), CAR_TYPE NUMBER(1),...
2
by: Troels Thomsen | last post by:
Hello, I am wondering if I can write some code, that allows me to call functions in the console , IDLE, without using the paranthesis notation. Like print. This will improve "intreractive'ness"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.