Link to home
Start Free TrialLog in
Avatar of Mickeys
MickeysFlag for Sweden

asked on

20 questions A,B,C and D

Hi,

I have some questions I need to have double checked. I have already done them but I need to see so it is the same answer I have before returning them.


MULTIPLE CHOICE
You can skip questions about interface and abstract classes!
1. When an "is a" relationship exists between objects, it means that the specialized object has
a.
some of the characteristics of the general class, but not all, plus additional characteristics.
b.
some of the characteristics of the general object, but not all.
c.
none of the characteristics of the general object.
d.
all the characteristics of the general object, plus additional characteristics.
ANS: _____


2. Which of the following statements declares Salaried as a derived class of PayType?
a.
public class Salaried : PayType
b.
public class Salaried :: PayType
c.
public class Salaried derivedFrom(Paytype)
d.
public class PayType : Salaried
ANS: _____


3. If ClassA is derived from ClassB, then
a.
public and private members of ClassB are public and private, respectively, in ClassA
b.
public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
c.
neither public or private members in ClassB can be directly accessed in ClassA
d.
private members in ClassB are changed to protected members in ClassA
ANS: _____



4. In UML diagrams, inheritance is shown
a.
With a line that has an open arrowhead at one end that points to the base class
b.
With a line that has an open arrowhead at one end that points to the derived class
c.
With a line that has a closed arrowhead at one end that points to the base class
d.
With a line that has a closed arrowhead at one end that points to the derived class
ANS: _____



5. If a derived class constructor does not explicitly call a base class constructor,
a.
it must include the code necessary to initialize the base class fields.
b.
the base class fields will be set to the default values for their data types.
c.
C# will automatically call the base class's default constructor immediately after the code in the derived class's constructor executes.
d.
C# will automatically call the base class's default constructor just before the code
in the derived class's constructor executes.
ANS: _____



6. A protected member of a class may be directly accessed by
a.
methods of the same class
b.
methods of a derived class
c.
methods in the same namespace
d.
All of the above.
ANS: _____



7. When declaring class data members, it is best to declare them as
a.
private members
b.
public members
c.
protected members
d.
restricted members
ANS: _____



8. If a class contains an abstract method,
a.
you cannot create an instance of the class
b.
the method will have only a header, but not a body, and end with a semicolon
c.
the method must be overridden in derived classes
d.
All of the above
ANS: _____


9. All fields declared in an interface
a.
are const and static
b.
have protected access
c.
must be initialized in the class implementing the interface
d.
have private access
ANS: _____



10. When one object is a specialized version of another object, there is this type of relationship between them.
a.
"has a"
b.
"is a"
c.
direct
d.
"contains a"
ANS: _____



11. A derived class can directly access
a.
all members of the base class
b.
only public and private members of the base class
c.
only protected and private members of the base class
d.
only public and protected members of the base class
ANS: _____



12. In the following statement, which is the base class?
public class ClassA : ClassB , ClassC
a.
ClassA
b.
ClassB
c.
ClassC
d.
Cannot tell
ANS: _____



13. In UML diagrams, inheritance is shown
a.
with a line that has an open arrowhead at one end that points to the base class.
b.
with a line that has an open arrowhead at one end that points to the derived class.
c.
with a line that has a closed arrowhead at one end that points to the base class.
d.
with a line that has a closed arrowhead at one end that points to the derived class.
ANS: _____



14. If a base class does not have a default constructor or a no-arg constructor,
a.
then a class that inherits from it, must initialize the base class values.
b.
then a class that inherits from it, must call one of the constructors that the base class does have.
c.
then a class that inherits from it, does not inherit the data member fields from the base class.
d.
then a class that inherits from it, must contain the default constructor for the base class.
ANS: _____



15. Protected members are
a.
not quite private
b.
not quite public
c.
Both A and B
d.
Neither A or B
ANS: _____



16. Protected class members are denoted in a UML diagram with the symbol
a.
*
b.
#
c.
+
d.
-
ANS: _____



17. In a class hierachy
a.
the more general classes are toward the bottom of the tree and the more specialized
are toward the top.
b.
the more general classes are toward the top of the tree and the more specialized are toward the bottom.
c.
the more general classes are toward the left of the tree and the more specialized are toward the right.
d.
the more general classes are toward the right of the tree and the more specialized are toward the left.
ANS: _____



18. If a class contains an abstract method,
a.
you must create an instance of the class
b.
the method will have only a header, but not a body, and end with a semicolon
c.
the method cannot be overridden in derived classes
d.
All of the above.
ANS: _____


19. In an interface all methods have
a.
private access
b.
protected access
c.
public access
d.
namespace access
ANS: _____



20. Which of the following statements correctly specifies three interfaces:
a.
public class ClassA : Interface1, Interface2, Interface3
b.
public class ClassA : [Interface1, Interface2, Interface3]
c.
public class ClassA : (Interface1, Interface2, Interface3)
d.
public class ClassA : Interface1 Interface2 Interface3
ANS: _____


TRUE/FALSE
1. It is not possible for a base class to call a derived class method.
ANS: _____

2. If a method in a derived class has the same signature as a method in the base class, the derived class method overloads the base class method.
ANS: _____

3. Every class is either directly or indirectly derived from the Object class.
ANS: _____

4. An abstract class is not instantiated, but serves as a base class for other classes.
ANS: _____

5. In an inheritance relationship, the derived class constructor always executes before the base class constructor.
ANS: _____

6. If two methods in the same class have the same name but different signatures, the second overrides the first.
ANS: _____

7. All methods in an abstract class must also be declared abstract.
ANS: _____

8. When an interface variable references an object, you can use the interface variable to call all the methods in the class implementing the interface.
ANS: _____
Avatar of abel
abel
Flag of Netherlands image

Sorry, this looks like an assignment for homework, and EE guidelines do not permit us doing your homework for you.
Avatar of Mickeys

ASKER

???? It is a paper I have got and I am trying to figure out if I have answered them correctly. If I publish what I have answed it is then possible to get if it is correct or if something is wrong? Otherwise I dont understand how to get help with this kind of questions.
Avatar of Guy Hengel [angelIII / a3]
yes, if you show your answers (and eventually some explanation about why you selected that particular answer), we can comment on them.
this will show that you put some effort on your homework/exam/paper/whatever, and basically, if you did the effort, most answers shall be correct (unless you fall into the traps of such multiple-choice questionaires)
@Mickeys: I see that you've been around here for a while (since 99), so I'm sure you know the way EE works. 20 questions is a lot, even if we just do it because we like it. And a sentence like "You can skip questions about interface and abstract classes!" on top doesn't help taking away the feeling of it being an assignment or online test. Btw, this style of multiple choice is typical for online tests, because it is very theoretical and there's very little room for ambiguity.

Tell us what questions you have trouble with or doubt your correct answer. If it is from an online test or paper, show the link to the test so we can look it up for easier reference.
Avatar of Mickeys

ASKER

Godmorning,

Ah great. So I can get help. :-) Here is all the questions with my answers on it. Is something wrong?

abel: It is not an online test. This is a paper that we could use to study questions for coming tests....the stupied thing is that we dont get the correct answers with the paper. I dont want to learn the questions if they a wrong. :-)

1. When an "is a" relationship exists between objects, it means that the specialized object has
a.
some of the characteristics of the general class, but not all, plus additional characteristics.
b.
some of the characteristics of the general object, but not all.
c.
none of the characteristics of the general object.
d.
all the characteristics of the general object, plus additional characteristics.
ANS: ___B__


2. Which of the following statements declares Salaried as a derived class of PayType?
a.
public class Salaried : PayType
b.
public class Salaried :: PayType
c.
public class Salaried derivedFrom(Paytype)
d.
public class PayType : Salaried
ANS: __A___


3. If ClassA is derived from ClassB, then
a.
public and private members of ClassB are public and private, respectively, in ClassA
b.
public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA
c.
neither public or private members in ClassB can be directly accessed in ClassA
d.
private members in ClassB are changed to protected members in ClassA
ANS: _B____



4. In UML diagrams, inheritance is shown
a.
With a line that has an open arrowhead at one end that points to the base class
b.
With a line that has an open arrowhead at one end that points to the derived class
c.
With a line that has a closed arrowhead at one end that points to the base class
d.
With a line that has a closed arrowhead at one end that points to the derived class
ANS: __C___



5. If a derived class constructor does not explicitly call a base class constructor,
a.
it must include the code necessary to initialize the base class fields.
b.
the base class fields will be set to the default values for their data types.
c.
C# will automatically call the base class's default constructor immediately after the code in the derived class's constructor executes.
d.
C# will automatically call the base class's default constructor just before the code
in the derived class's constructor executes.
ANS: _D____



6. A protected member of a class may be directly accessed by
a.
methods of the same class
b.
methods of a derived class
c.
methods in the same namespace
d.
All of the above.
ANS: ___D__



7. When declaring class data members, it is best to declare them as
a.
private members
b.
public members
c.
protected members
d.
restricted members
ANS: ___A__



8. If a class contains an abstract method,
a.
you cannot create an instance of the class
b.
the method will have only a header, but not a body, and end with a semicolon
c.
the method must be overridden in derived classes
d.
All of the above
ANS: __D___


9. All fields declared in an interface
a.
are const and static
b.
have protected access
c.
must be initialized in the class implementing the interface
d.
have private access
ANS: __C___



10. When one object is a specialized version of another object, there is this type of relationship between them.
a.
"has a"
b.
"is a"
c.
direct
d.
"contains a"
ANS: __A___



11. A derived class can directly access
a.
all members of the base class
b.
only public and private members of the base class
c.
only protected and private members of the base class
d.
only public and protected members of the base class
ANS: __D___



12. In the following statement, which is the base class?
public class ClassA : ClassB , ClassC
a.
ClassA
b.
ClassB
c.
ClassC
d.
Cannot tell
ANS: __B___



13. In UML diagrams, inheritance is shown
a.
with a line that has an open arrowhead at one end that points to the base class.
b.
with a line that has an open arrowhead at one end that points to the derived class.
c.
with a line that has a closed arrowhead at one end that points to the base class.
d.
with a line that has a closed arrowhead at one end that points to the derived class.
ANS: ___C__



14. If a base class does not have a default constructor or a no-arg constructor,
a.
then a class that inherits from it, must initialize the base class values.
b.
then a class that inherits from it, must call one of the constructors that the base class does have.
c.
then a class that inherits from it, does not inherit the data member fields from the base class.
d.
then a class that inherits from it, must contain the default constructor for the base class.
ANS: __C___



15. Protected members are
a.
not quite private
b.
not quite public
c.
Both A and B
d.
Neither A or B
ANS: __C___



16. Protected class members are denoted in a UML diagram with the symbol
a.
*
b.
#
c.
+
d.
-
ANS: __D___



17. In a class hierachy
a.
the more general classes are toward the bottom of the tree and the more specialized
are toward the top.
b.
the more general classes are toward the top of the tree and the more specialized are toward the bottom.
c.
the more general classes are toward the left of the tree and the more specialized are toward the right.
d.
the more general classes are toward the right of the tree and the more specialized are toward the left.
ANS: __C___



18. If a class contains an abstract method,
a.
you must create an instance of the class
b.
the method will have only a header, but not a body, and end with a semicolon
c.
the method cannot be overridden in derived classes
d.
All of the above.
ANS: __A___


19. In an interface all methods have
a.
private access
b.
protected access
c.
public access
d.
namespace access
ANS: ___C__



20. Which of the following statements correctly specifies three interfaces:
a.
public class ClassA : Interface1, Interface2, Interface3
b.
public class ClassA : [Interface1, Interface2, Interface3]
c.
public class ClassA : (Interface1, Interface2, Interface3)
d.
public class ClassA : Interface1 Interface2 Interface3
ANS: __A___


TRUE/FALSE
1. It is not possible for a base class to call a derived class method.
ANS: __T___

2. If a method in a derived class has the same signature as a method in the base class, the derived class method overloads the base class method.
ANS: __F___

3. Every class is either directly or indirectly derived from the Object class.
ANS: ___T__

4. An abstract class is not instantiated, but serves as a base class for other classes.
ANS: __T___

5. In an inheritance relationship, the derived class constructor always executes before the base class constructor.
ANS: ___F__

6. If two methods in the same class have the same name but different signatures, the second overrides the first.
ANS: __T___

7. All methods in an abstract class must also be declared abstract.
ANS: ___T__

8. When an interface variable references an object, you can use the interface variable to call all the methods in the class implementing the interface.
ANS: __F___
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mickeys

ASKER

Thank you so much for helping me out. I will sit down and read throw everytning and learn from a real teacher (you) :-)
>  I will sit down and read throw everytning and learn from a real teacher (you) :-)

:)
Glad I could've been of some help.
>1B should be 1D
indeed


>5D... impossible to answer, answers (c,d) do not match question and (a,b) are wrong, however, D is closest to correct imo...
actually, 5D is correct AFAIK

>6D, not correct, but there's no correct answer. Both A and B are good.
actually, option C is good also, so 6D is correct for me

>7A depends on your school of thought... the term for "data members" should be "fields"
I do agree on 7A, as by default, data members should not be visible to "outside world" unless you need to have a different behavior

>8D no correct answer exists, ...
actually, 8D is correct!

>9C this is total rubbish! Interfaces cannot contain fields (try it, you get a CS0525 in C#)
well, you have to remember that you are answering a microsoft-style questionaire.
I am not sure if it will raise a compile error or not, but from the docs, I would deduct that the fields have private access (and hence are completely useless, actually) http://msdn.microsoft.com/en-us/library/87d83y5b(VS.80).aspx
my choice would hence by 9D.

>10A i think should be B, but "specialized version of" is not an OO term and hence this this is a guessing game (inheritance? aggregation?)....
10B indeed.

>12B, should be D, because the statement is illegal with classes
12B is correct. the name ClassB does not make it a class (remember, it's ms trapping :)
same link: http://msdn.microsoft.com/en-us/library/87d83y5b(VS.80).aspx
>>When a base type list contains a base class and interfaces, the base class must come first in the list.


>15C q. is total rubbish, there's no reasonable answer
15C is correct, IMHO.
private = nobody else can see/use the method/property
public = everybody else can see/use the method/property
protected = some specific code can see/use the method
not rocket science question, I do agree !


>18A is wrong, but there are no correct answers
18B is correct. only a abstract class can have abstract methods, hence the description of B is correct.
anyhow, A and C are definitively wrong, so B would have been my choice by exclusion

>1T should be F. This depends on what the question means by "calling a method". There are many ways to call a derived classes method, though not through the inheritance tree...
I disagree here. the base class (A) cannot call a method of a class (B) that inherits (A), as (A) has to be compiled "before" (B) in order to have the "interface" ready. trying to do this would be a cyclic reference problem.

>2F should be T,
agreed

>6T should be F (this is called overloading)
agreed

>7T should be F (abstract classes can contain concrete methods)
Agreed.
http://msdn.microsoft.com/en-us/library/aa664435(VS.71).aspx 
>Abstract method declarations are only permitted in abstract classes
does not exclude that abstract classes have non-abstract methods

>8F question is total rubbish, there's no such thing as an interface variable.
8F would be my choice.
I presume what is meant is a variable that is declared with the data type of the interface.
which does not allow you to directly call the derived class methods (at least not without casting)
aka:
IInterface var = new ClassImplementingIInterface();
var.MethodofClassImplementingIInterface();  // does not work -> answer to question
(ClassImplementingIInterface var).MethodofClassImplementingIInterface(); // would work


Avatar of Mickeys

ASKER

Thanks for your feedback. I will compare it to abel:s answers.
Hi Angel, though you make some very good critical observations, I can't resist entering the discussion at some points here (the ones where we disagreed, of course)   ;-)

@5 you say: actually, 5D is correct AFAIK

I said: "does not match the question". Because a default constructor is a private constructor in C#, unless you make it explicitly public or protected. So, it depends on the code and the question needs tweaking. The following example will not compile:

    public class TestBase
    {
        public TestBase(string bla) { }
    }
    public class TestChild : TestBase
    {
        public TestChild(int someInt) { }   // error CS1729
    }

@6 you say: actually, option C is good also, so 6D is correct for me

and I said that only a and b are good. C says "protected member is accessible to any class in the namespace". There is no access modifier that restricts to a namespace:

   public: no restriction
   protected: restricted to containing class and derived classes
   internal: restricted to classes in assembly (note that this is different from "namespace")
   protected internal: restricted to any class in assembly and any derived classes
   private: only containing class

See also: http://msdn.microsoft.com/en-us/library/ba0a1yw2.aspx

@7 you say: I do agree on 7A, as by default, data members should not be visible to "outside world" unless you need to have a different behavior

and I said it depends on your school of thought. I take that back. It depends onmany things: whether you use constant fields or constant statics, which can and should be public (see Uri, String and Int class). Non-constant fields can also be internal or even protected, depending on your design (see Int (m_value) and TimeSpan (ticks)). Where internal will often have the preference (it is impossible to access by people having your assembly, even if they derive from your class).

@8: you say: actually, 8D is correct!

and I said: no correct answer exists, but A & C are correct. That was wrong. C is only partially correct: you can have derived classes that do not overload the abstract methods.

And B is partially correct also: "a class cannot contain an abstract method, unless the class itself is called abstract", which is not what is said in the question: "if a class contains an abstract method ...": it will not compile. Q.E.D.  ;-)

@9 you refer to http://msdn.microsoft.com/en-us/library/87d83y5b(VS.80).aspx, which says:
An interface can be a member of a namespace or a class and can contain signatures of the following members:    Methods, Properties, Indexers, Events.
if you try to add a field, the interface will not compile. Hence, the only correct answer to "All fields declared in an interface" is: it cannot be done. Not even static fields (which works in Java), as this will not compile:

    interface SomeInterface
    {
        public static const string bla = "";   // CS0525 "Interfaces cannot contain fields"
    }

@12 you say: 12B is correct. the name ClassB does not make it a class (remember, it's ms trapping :)

I agree, but if you "trap" like that... You are serious about that MS questionnaires contain silly things like that? It's an insult to your intelligence, that's what it is!

@15 you think C (not quite public/private).

I said: this is rubbish. There's no definition for "not quite". Does it mean more private or less private? If this definition is correct, then "internal" is also "not quite public/private". Deduction then gives us "internal == protected"???? Anyway, I stick to mine "it's rubbish" lol

@18 you say: 18B is correct. only a abstract class can have abstract methods, hence the description of B is correct.

I think you mean here: "hence the description of B is incorrect", because there's no mention of an abstract class in the question, hence "a class cannot have an abstract method", only "an abstract class can have zero or more abstract methods/properties etc".

If you have to answer the question, I agree that B i most likely meant as correct answer...

//// TRUE / FALSE questions \\\\

@1 amongst more, you say "trying to do this would be a cyclic reference problem."
in my answer, I say "it depends on what you mean by calling a method". Consider this example, it will compile and run and there's no cyclic reference problem; the base class can call a method of a derived class:

    public class TestBase
    {
        public TestBase() { }
        public void DoSomethingWithChild(TestChild someChild) {
            someChild.someProp = "test";
        }
    }
    public class TestChild : TestBase
    {
        public string someProp { get; set; }
        public void DoSomething()
        {
            DoSomethingWithChild(this);
        }
    }

@8 you have a different reading of the question. I said there's no such thing as in interface variable, and you say that it is a variable declared with the type of an interface, which of course is possible.

Making matters worse: in the Java world, an interface variable is a constant that is declared on an interface (as I noted earlier, in Java you can have constants and statics on an interface). In C# that is not possible, which is why I said there's no such thing.

I like your reading of that last question, though I still consider it a poor question that requires out-of-band thinking beyond the question definition, which is something that half of all the questions here required.... :S



-- Abel --
Avatar of Mickeys

ASKER

*hehe* Great comments. I do learn alot by all this. :-) One thing I am sure of is that it is a really bad quiz. :-) to learn C#.
indeed it is :)
@5: actually, the scope of a constructor does not matter, as it called implicitly!

@6: the issue is the understanding of the question and it's answers.
the "protected" does not "limit" to the namespace, actually. however, all classes that are in the namespace have access. there might be other classes in other namepaces, but that case is not excluded by answer C... so, 6C is good also (at least, it's not wrong)

@8: as for @6: as long as a "answer" is not wrong, it has to be considered correct. you might name it "partially correct"...

@9: I am not sure if it compiles or not, maybe that behavior has changed between versions.


@12 you say: 12B is correct. the name ClassB does not make it a class (remember, it's ms trapping :)
>I agree, but if you "trap" like that... You are serious about that MS questionnaires contain silly things >like that? It's an insult to your intelligence, that's what it is!
call it trap if you wish, the issue is that the questionnaires are built that way. also, to exclude people that do just learn brain-dumps trying to pass the exams without understanding the material.
only by having understood the concepts that you can pass those questions


@18 I will rephrase to "hence the description of B can be applied


T/F@1: interesting example... I wonder how that could be compiled, from the point of view of a compiler
I presume the compiler would first build up the interface of TestBase (pass), then TestChild (pass), and the compiles each method code, which will also pass.
I really doubt any real-life implementation scenario for this...

T/F@8: resp all the comments:
as I have taken plenty of MS (and other software exams, check my profile to see which status I got, not all individual exams though), and I managed to pass them all on the first "try" except 2, where I was send before I finished my preparations, I think I am kind of an expert of understanding how the exams "work".
it does not mean that I am 200% sure of all the answers I give here, but at least, I can answer plenty of the question by cross-checking some knowledge from all my different preparations, along with a good basic understanding of general programming concepts.
I don't (and won't) agree on all being correct. but at least, I am aware of both the concept and the issues around them.

regards,
Angel, I value your knowledge and your long-standing status as #1, and I like it that you know a way to interpret these questions. It explains to me why I stepped away once I had my couple of dozens of certificates, because I was done with it (though I must say that some of the brainbench.com tests are really good, maybe they are an exception).

But apart from knowing what the possible answer should be, I think it is also good to step aside and look at the questions. Some of them just talk nonsense (in the light of C#, I mean) and maybe that's on purpose, but still... Anyway, discussing them is good and reveals some of the misunderstandings that are around coding in C#.

Mainly the first one above (@5): I wouldn't have said what I said if I hadn't tested and verified it. Even though it is called implicitly, the compiler will complain (with an error, not a warning) and you cannot compile.

Another thing on @6: I agree to your reading of the question (though I do not agree to the question, it is still plain wrong imo), but don't mix things up: "all classes in the namespace have access to protected members" is just not true:

public classA {
     protected void doSomething() {}
}
public classB {
     private void callDoSomething{
          classA clsa = new classA();
          clsa.doSomething();                     // compile error
     }
 }
 
I will leave it now to that. To the other points I second your thoughts, anyway.

You seem to have one question yourself though, on T/F nr 1: the circular reference. Yet it is quite common, consider this DOM example, which works in most OO languages, and contains loads of circular references:

XmlDocument doc = new XmlDocument();
doc.Load("some.xml");
XmlNode node = doc.DocumentElement.FirstChild.FirstChild.Parent.Parent;

which will return the document element :)

Regards,
-- Abel --