473,326 Members | 2,013 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,326 software developers and data experts.

Which is True?

Which of the following statements are true about constructors and methods?

A constructor has it's own name, a return type and is invoked using the new operator.
A function has it's own name, a return type and is invoked using the dot operator.
A constructor has the name of the class, no return type and is invoked using the new operator.
1 & 2
2 & 3
1, 2 & 3

None of the statements are true
Nov 15 '08 #1
6 1124
JosAH
11,448 Expert 8TB
And what do *you* think?

kind regards,

Jos
Nov 15 '08 #2
The answer is 2&3 are true
Nov 16 '08 #3
JosAH
11,448 Expert 8TB
The answer is 2&3 are true
Expand|Select|Wrap|Line Numbers
  1. class B { 
  2.    void mb() { ... } 
  3. }
  4. class D extends B { 
  5.    void md() { ... }
  6.    public void test() {
  7.       mb(); // no dot
  8.       md(); // no dot
  9.    }
  10. }
  11.  
The dot isn't always needed ...

kind regards,

Jos
Nov 16 '08 #4
myusernotyours
188 100+
Expand|Select|Wrap|Line Numbers
  1. class Foo{
  2.  
  3. public Foo(){
  4. ...
  5. if(x == b)
  6. return; // Legal
  7.  
  8. //If we are here continue doing stuff...
  9. ...
  10. ...
  11.  
  12. }
  13.  
  14. public void jump(){
  15. ....
  16. ....
  17. return; // Legal but not nessesarily nessesary.
  18. }
  19.  
  20. public boolean sleep(){
  21. ...
  22. ...
  23. return true; // Mandatory
  24. }
  25. }
  26.  
  27.  
So does the method jump have a return type?
Void indicates only the absence of a return type. It's not a type. The compiler does not even expect us to return, because there is nothing to return.

Can we therefore say the constructor Foo() and the method jump() are the same in terms of return types in that they both return nothing? The only thing perhaps would be that the compiler ALWAYS insists on a constructor returning nothing (void) so we don't even have to say. But a method may return a value.
But then why did sun insist on using void where there is no Return Type in methods?? Why not do it just like for the constructor??

Rgds

Alex.
Nov 17 '08 #5
JosAH
11,448 Expert 8TB
But then why did sun insist on using void where there is no Return Type in methods?? Why not do it just like for the constructor??
To keep the C and C++ programmers happy. There are many many things that
could have been solved in another way but Java wants to look similar to those
two other programming languages.

kind regards,

Jos
Nov 17 '08 #6
myusernotyours
188 100+
To keep the C and C++ programmers happy. There are many many things that
could have been solved in another way but Java wants to look similar to those
two other programming languages.

kind regards,

Jos
Happy are the meek for they shall see god.

rgrds

Alex.
Nov 17 '08 #7

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

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
52
by: Darklight | last post by:
Question: Write a function named sumarrays() that accepts two arrays that are the same size. The function should add each element in the array together and place the values in the thrid array. ...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
6
by: Markus Eßmayr | last post by:
Hello, I'd like to consume a WebService, which returns an array of objects which include several members of type System.String, System.Decimal and System.DateTime. In the WSDL-file, the members...
1
by: Pieter | last post by:
Hi, I have this Warning for several forms when using the DockPanel Suite of Weifen Luo in VS.NET 2005. I read a lot about this CLS-compliant stuff, but I don't now how to chech actually which...
2
by: cogitoergosum | last post by:
Hi, I have a table with four columns. By default, except for the second column (id="s01") all column values are protected. When a value is selected from second column, the third column is...
1
by: esd | last post by:
Hello folks, the two code blocks below do the same thing, which is set a few form field values. Clearly the first method is the most elegant but my question is which is best in terms of lightest...
0
by: readnlearn | last post by:
hai, i have written this below code for displaying captcha image whenever i entered incorrect uname,password in login page. for that i disable the controls of captcha like textbox,labels,button and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.