if you had something like this
I know Blah() is a constructor, but the class Blah is not right?Code:class Blah { void Blah() { } Blah() { } }
if you had something like this
I know Blah() is a constructor, but the class Blah is not right?Code:class Blah { void Blah() { } Blah() { } }
The second Blah() is a constructor, yes.
Of course the class isn't a constructor. A constructor is a method that sets up an instance of its class to be ready for use.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
SO it has 2 constructors right?
I read somethign about what the void meant and didnt really understand it, can you try and explain it to me?
Also what does encapsulated mean?
No, only one constructor. The other method has a return type, so it's just a standard instance method.SO it has 2 constructors right?It's the return type declared when a method doesn't return a value.I read somethign about what the void meant and didnt really understand it, can you try and explain it to me?Also what does encapsulated mean?I can't be any more specific without context.encapsulate
v 1: enclose in a capsule or other small container
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Would this be tightly encapsulated?
so void Blah() is not a constructor since it does not return a value?
if im not mistaken an instance variable would be like String or int right?
Last edited by craigtb; 01-30-2007 at 06:45 PM.
"Tight encapsulation" refers to making the innards of the class as inaccessible to outside objects as possible. The idea is that this promotes the design of classes with consistent and powerful interfaces (I don't use the term in its Java sense) whose use requires no knowledge of the workings of the class.Would this be tightly encapsulated?No, it's not a constructor because it has a defined return type. The fact that that return type is void is neither here nor there.so void Blah() is not a constructor since it does not return a value?An instance variable (known as a property in Java parlance) is any property that belongs to instances of the class, as opposed to, say, a local variable in a function or a static property (which belongs to the class itself).if im not mistaken an instance variable would be like String or int right?
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
so like
that would have 2 instance variables?Code:public Blah { private double height, distance; void Blah() {} Blah() {} }
Yes, height and distance.however, is a syntax error. Since it's a class, you cannot omit the class keyword:Code:public BlahCode:public class Blah {
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
OK thanks!
If i was to write a constructor for a class PersonInfo would it be somehting like this?
Code:class PersonInfo { private String name, address; private int income; PersonInfo() { return name; \ return address; im not sure about this way of writing it return income; / } }
Last edited by craigtb; 01-30-2007 at 09:51 PM.
Bookmarks