Check if true | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Check if true

Please chech wether these java statments are or not. If not please give reasons St 1 whenever an object of that class is created, the attribute attribute will be set to same. St 2 You have to give vlaue to each attribute of object St 3 Constructors give value to attribute of object of created class St 4 The setter methods inside the constructors can be used to set the attribute values St 5 You can not set objects when you use constructors (specail methods)

11th Apr 2020, 7:35 AM
Abdul Manan Jutt
Abdul Manan Jutt - avatar
6 Answers
+ 1
I'm telling with the OOP perspective. There might be some exception in Java. St1. Attribute will be set to their default values. If we don't write constructor compiller will automatically write it. If we have written constructor, it will use give values to initialize object.
12th Apr 2020, 3:18 AM
C ++
C ++ - avatar
+ 1
St2. No. They can be default. But having a attribute which you don't use anywhere is a bad practice but still it is not an syntax error.
12th Apr 2020, 3:20 AM
C ++
C ++ - avatar
+ 1
St3. False. Class is just structure. It cannot be created and distroyed ... Objects are created from the class. Constructor is used to construct the object. It first create object then assign values to its attributes. If you want to initialize its variables (Attribute) use the initializer list.
12th Apr 2020, 3:24 AM
C ++
C ++ - avatar
+ 1
St4. Yes. Because constructor first create object then assign values. Therefore all the methods of that object can be called on it. Even inside constructor. Just consider the order in which you use them specially if you are using some method which use some other attribute. You have to first assign that attribute value. Otherwise it will lead to logical error
12th Apr 2020, 3:28 AM
C ++
C ++ - avatar
+ 1
St5. I don't get this one... Please explain more
12th Apr 2020, 3:29 AM
C ++
C ++ - avatar
0
Thanks C ++
13th Apr 2020, 10:51 PM
Abdul Manan Jutt
Abdul Manan Jutt - avatar