in Education by
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago. Improve this question My relative is studying programming and has a hard time understanding classes. He has trouble understanding for example that you need to instantiate it, that methods cannot access variables in other methods and if you change a variable in one instance of a class it doesn't change for other instances. I've tried to use analogies like a class definition is like a blueprint of a house. And instances are houses made from that blueprint. How do you explain classes and OO in general? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Seriously use Animals, it works great. And that's what nailed the concept for me years ago. Just found this C# code. It seems good // Assembly: Common Classes // Namespace: CommonClasses public interface IAnimal { string Name { get; } string Talk(); } // Assembly: Animals // Namespace: Animals public class AnimalBase { private string _name; AnimalBase(string name) { _name = name; } public string Name { get { return _name; } } } // Assembly: Animals // Namespace: Animals public class Cat : AnimalBase, IAnimal { public Cat(String name) : base(name) { } public string Talk() { return "Meowww!"; } } // Assembly: Animals // Namespace: Animals public class Dog : AnimalBase, IAnimal { public Dog(string name) : base(name) { } public string Talk() { return "Arf! Arf!"; } } // Assembly: Program // Namespace: Program // References and Uses Assemblies: Common Classes, Animals public class TestAnimals { // prints the following: // // Missy: Meowww! // Mr. Bojangles: Meowww! // Lassie: Arf! Arf! // public static void Main(String[] args) { List animals = new List(); animals.Add(new Cat("Missy")); animals.Add(new Cat("Mr. Bojangles")); animals.Add(new Dog("Lassie")); foreach(IAnimal animal in animals) { Console.WriteLine(animal.Name + ": " + animal.Talk()); } } } And once he's got this nailed, you challenge him to define Bird (fly), and then Penguin (fly!?)

Related questions

0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    I'm learning the Python programming language and I've come across something I don't fully understand. In a method ... know very much. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Could someone please demystify interfaces for me or point me to some good examples? I keep seeing interfaces ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Could someone please demystify interfaces for me or point me to some good examples? I keep seeing interfaces ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Could someone please demystify interfaces for me or point me to some good examples? I keep seeing interfaces ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Is there any reason for a class declaration to inherit from an object? I just found some code that does this ... class code follows... Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am a learner and just want to know the basic concept of super(). Here in the given code I want to know ... () ChildOne() ChildTwo() Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    There are two codes, what are the difference between them: Using type import types if type(q) is types. ... ): do_something_else() Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me the difference between a function decorated with @staticmethod and one with @classmethod? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    let's say i have an interface as below public interface ConditionChecker { boolean isInCondition(Person p); ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    let's say i have an interface as below public interface ConditionChecker { boolean isInCondition(Person p); ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    let's say i have an interface as below public interface ConditionChecker { boolean isInCondition(Person p); ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how much do Python programmers make? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
...