what is different between base class and child class?
A base class (or parent class, or superclass) is a class which one or more child classes inherits from; a child class (or sub-class) is one which inherits from a base class. Depending on the language, you may have some programmer-defined classes which have no base classes, or (more often) all programmer-defined classes may inherit implicitly from a global, abstract root class (often called
When a class inherits from another class, it is as if the properties and methods of the base class are copied into the child class; the child class 'inherits' all the properties and behaviors of the parent, but may add to them, and can override (replace) some or all of the methods of the parent class.
An object reference (i.e., a variable) of the parent class type may refer to members of its child classes, in which case any message (method call) can be sent to the object that the parent class declares, but the method used will be the one of the child class. That is to say, if I have
class Foo method a() method b() class Bar of Foo method b() // overrides Foo's b() method c() // adds a new method c() variable baz of Foo variable quux of Foo baz := new Foo() quux := new Bar() baz.a() // this uses the Foo method a() baz.b() // this uses the Foo method b() quux.a() // this uses the Foo method a() quux.b() // this uses the Bar method b() quux.c() // in most languages this would be an error!
This is known as polymorphism.
In C++, where there is an explicit difference between an object variable and an object reference, you need to explicitly use pointers to objects to get polymorphic behavior; furthermore, the polymorphic methods have to be explicitly declared as
virtual in order to get full polymorphism. In C#, variables of class types are always references, but you still need to declare polymorphic methods as
virtual in order for it to be in the virtual method table. Most other languages automatically allow any method to be polymorphic.
In most languages, there are provisions for abstract classes, ones which cannot be directly instantiated. In those cases, an object of the abstract class type can only refer to objects of a child class.
I have two tables, I will call them first-half and second-half (of the year)
Table: first id jan feb mar apr ----------------------- 2 80 90 70 60 3 50 40 60 30 Table: second id jan feb mar apr ----------------------- 2 50 70 60 90 3 80 60 50 ...
Hi when I tried to insert my output the void displayed null or 0 can you tell me what's wrong with my rpogram? tnx
My main program
int choice; public static void main(String args) Scanner absorb = new Scanner(System.in); // phase 1 login cloth cl = new ...
i am trying to create a library management system which is supposed to be used to store/keep infp for the library and the library members( book title, author, name and picture for borrower and other stuffs). The app has 6 buttons, delete, save, add,previsous,next, and upload( for upload ...