Explain to me the following Object-oriented concepts: class, object (and the difference between the two) instantiation method (as opposed to, say, a C function) virtual method, pure virtual method class/static method static/class initializer constructor destructor/finalizer superclass or base class subclass or derived class inheritance encapsulation multiple inheritance (and give an example) delegation/forwarding composition/aggregation abstract class
interface/protocol (and different from abstract class) method overriding method overloading (and difference from overriding) polymorphism (without resorting to examples) is-a versus has-a relationships (with examples) method signatures (what's included in one) method visibility (e.g. public/private/other)
Elementary stuff, and I hope that 2 or 3 examples will explain them well :-D \[\tiny\text{please no animal/car analogies :(}\]
Uh... not that I'm against explaining it - but maybe a textbook would be better? haha. I mean, there is a lot of content here.
a class is basically a definition of a group of things, an object is a thing that is part of a class. ex. Public Class automobile Public color As String Public doors As Integer Public fuel As Integer Public MPG As Integer Public Sub New(ByVal ncolor As String, ByVal ndoors As Integer, ByVal nfuel As Integer, ByVal nMPG As Integer) color = ncolor doors = ndoors fuel = nfuel MPG = nMPG End Sub Public Function travel() Return fuel * MPG End Function End Class this is a class. this class is called automobile. and really the only thing needed to make a class is the top part "public class automobile." from there you can give your class properties and functions. like if i want to see how far an automobile can travel i would write (Insert name of automobile here).travel and it would do that function. this is an example of an object. Module Module1 Sub Main() Dim truck As New automobile("white", 4, 28, 14) Dim van As New automobile("gold", 5, 22, 24) Dim Dtruck As New automobile("silver", 4, 30, 18) System.Console.WriteLine(truck.travel) End Sub End Module the truck, van, and Dtruck are all objects of the class "automobile." as you'll notice i've told the program to "System.Console.WriteLine(truck.travel)" that will take the MPG of the car and the capacity of the tank, multiply them, and print the answer on the screen. if you'll notice the colors and numbers after the dim () as new automobile. those are because in the class i called a (public sub new) and that makes it so i have to type in the specific info in that spot. also at the top of the class i wrote "public color as string" those are the properties basically. color is a property and so is fuel MPG and doors. and the rest of the stuff either i dont fully understand myself or i just dont know. :/ sorry. im a student myself :/ good luck!
Could have noted that Public Sub New() is a constructor :-D
haha to be honest i didnt know that. :) but thanks. now i do :)
Join our real-time social learning platform and learn together with your friends!