473,289 Members | 1,866 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,289 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 1123
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...

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.