Inheritance+Notes

Shashwat Notes on APCS:

Inheritance - One of the main technique of OOP (object-oriented programming)

Very general form of class is first defined and compiled, and then more specialized versions of the class are defined by adding instance variables and methods.

-- Said to inherit methods and instance variables of the general class. Inherits all public variables, constants, and methods not only public but also protected visibility modifiers

Super-class (parent class) (Base class) Sub-class (child class) (Derived class) Common variables for Elementary, Middle, High School student: Name, Grade, Age Common methods for Elementary, Middle, High School student: set, get, toString private variables for Elementary Section For using the constructor, you cannot just assume that it gets carried: you have to say super();

We use 'extend' good notes...

** Inheritance-Ishaan ** Superclass (parent) Public methods and non private variables are transferred to children.( subclass) -

Student: Name Grade Age Set,get, tostring Promote Elem(subclass) Section subclass can have its own methods, variables and constants.

Over riding methods means using an inherited method and changing the implementation for a specific subclass. Elem: Public void promote If (res.equalsto(“pass”) super.promote;  (orginal promote method is super promote good notes..write more details ..so later you can use them for your reading notes before examination

I mportiant note on inheritance classes. from MISTERUNKNOWN.

when the base class of the super class or a derived class above another derived class is deleted. the other classes down the line will be ineffective without the inheritence needed to be recieved from their predecessors. write all the details... there are lot more that we learned about Inheritance.

Inheritance Notes - Sruti

>
 * Inheritance is the main technique of Object-Oriented Programming (OOP).
 * One class inherits the characteristics of another. characteristics???? say public,protected variables and methods
 * Subclass also known as child class and derived class inherits from a Superclass also known as Base class and parent class.
 * All public methods and variables of Superclass are available to Subclass public and protected methods
 * Subclass inherits the public method, public variable and public constants but not private.
 * A subclass can have its own variables and methods. apart from the variables and methods inherited from the super class
 * Methods can be overridded= overridden in subclass.
 * A derieved class automatically has all the instance variables and methods that the base class has, as well as additional methods and/or instance variables. --- the right way of saying this will be a derived class automatically inherits or derives all the public or protected vairables and methods from the base class. You can also add additional variables and methods to the sub class..
 * Inheritence is advantageous because it allows a code to be reused without copying it again.

Multiple Inheritence - having multiple parents not allowed in JAVA


 * A child can be a parent for another class.
 * A child cannot inherit from two classes.

For Inheritence


 * The general form of a class is defined and compiled.
 * Then a specific version of the class is defined by adding instance variables and methods.

Definition

good notes...
 * Inheritence is a proccess by which a new class in created from another class.

Sitara, Inheritance notes


 * inheritance is one of the main techniques of object oriented programming
 * using this technique a very general form of a class is first defined and compiled, and then more specialized versions of the class are defined by adding instance variables and methods
 * the specialized classes are said to inherit the methods and instance variables of the general class
 * child = subclass, parent = superclass
 * super class has public methods and variables, NOT PRIVATE! - not correct....super class has both private and public method and variables....
 * Subclass inherits the public variables, methods, and constants, not private!
 * Example: Student, name, grade, age, set, get tostring, promote
 * Subclass = elementary student, all methods of student class, section, class teacher, basic in addition to its own additional variables and methods
 * Inheritance is the process by which a new class is created from another class
 * New class = derived class
 * Original = base class
 * Derived class automatically has all the instance variables and methods that the base class has, and it can have additional methods or instance variables as well
 * Inheritance is especially advantageous because it allows code to be reused without having to copy it into the definitions of the derive good notes...