anonymous
  • anonymous
look at the both programs Carefully
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
1- public class scannerClass { scannerClass (int a) // a constructor which print value a { int av; av=a; System.out.println(a); } public static void main(String ar[]) {int k; scannerClass a = new scannerClass(32); //value is pass directly when object is created //a.??? only Object class method will be shown }} 2- public class scannerClass { int ScannerClass(int a) //constructor with return type { int av; av=a; System.out.println(a); return a; } public static void main(String ar[]) {int k; //scannerClass a = new scannerClass(32);-error //here we cant pass value directly scannerClass a = new scannerClass(); a.ScannerClass(322); a.ScannerClass(32); } In first program we cant pass value by using object 'a' . where 2nd we cant pass value by directly when object is created why there is difference in between both programs ?
eSpeX
  • eSpeX
The first thing I would ask is that you include the error you are given in the second class example. The information you give sounds as though it is not seeing your constructor and thus calling a default constructor. Also, you do not have any class member functions so once the instance is created you have no means of manipulating the variables. Try adding "set/get" functions instead of creating two instances of the class with the same name.
rsmith6559
  • rsmith6559
AFAIK, neither constructors or destructors can return values. They're just for initializing / cleaning up.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

eSpeX
  • eSpeX
@rsmith6559 is correct, constructors and destructors are part of the family of functions that do not return a value, as is the void function. Which does explain why your second program is calling a default constructor.
anonymous
  • anonymous
@eSpeX u mean in second program which have a constructor with return type it is not constructor at all and when we calling the object 'a' which are created is calling a default constructor ?
eSpeX
  • eSpeX
@thangeram Yes, where you have "int ScannerClass(int a) //constructor with return type", this is an illegal form for a constructor and most likely the reason you are unable to issue the "a.ScannerClass(322);" command since the default constructor the compiler is using takes no parameters, ScannerClass(void).
anonymous
  • anonymous
ok @eSpeX then the program assum as another function unlike constructor and thats y we can call a.ScannerClass(322) thanx everyone :)

Looking for something else?

Not the answer you are looking for? Search for more explanations.