SlideShare una empresa de Scribd logo
1 de 6
03: Inherit Bank Account Class as Saving & Current


AIM            : A class derived from Account that holds information about saving and current
account also implements overrides method and print summary of saving and current account.

OBJECTIVE                       : To expose the concepts of inheritance and overriding.


THEORY
    Inheritance: -Inheritance is one of the cornerstones of object-oriented programming
because it allows the creation of hierarchical classifications. Using inheritance, you can create a
general class that defines traits common to a set of related items. This class can then be inherited
by other, more specific classes, each adding those things that are unique to it. In the terminology
of Java, a class that is inherited is called a superclass. The class that does the inheriting is called a
subclass. Therefore, a subclass is a specialized version of a superclass. It inherits all of the
instance variables and methods defined by the superclass.

Inheritance Basics: - To inherit a class, you simply incorporate the definition of one class
into another by using the ‘ extends’ keyword. To see how, let’s begin with a short example. The
following program creates a superclass called A and a subclass called B. Notice how the keyword
extends is used to create a subclass of A.



                // A simple example of inheritance.
                // Create a superclass.
                class A {
                int i, j;
                void showij() {
                System.out.println("i and j: " + i + " " + j);
                }}
                // Create a subclass by extending class A.
                class B extends A {
                int k;
                void showk() {
                System.out.println("k: " + k);}
                void sum() {
                System.out.println("i+j+k: " + (i+j+k));

                                                                                                      17
SDTL
04: Inherit Bank Account Class as Saving & Current


               }}
               class SimpleInheritance {
               public static void main(String args[]) {
               A superOb = new A();
               B subOb = new B();
               // The superclass may be used by itself.
               superOb.i = 10;
               superOb.j = 20; System.out.println("Contents
               of superOb: "); superOb.showij();


               System.out.println();
               /* The subclass has access to all public members of
               its superclass. */
               subOb.i = 7;
               subOb.j = 8;
               subOb.k = 9;
               System.out.println("Contents of subOb: ");
               subOb.showij();
               subOb.showk();
               System.out.println();
               System.out.println("Sum of i, j and k in subOb:");
               subOb.sum();
               }}
       The output from this program is shown here:
       Contents of superOb:
       i and j: 10 20
       Contents of subOb:
       i and j: 7 8
       k: 9
       Sum of i, j and k in subOb:
       i+j+k: 24



                                                                                                          18
SDTL
04: Inherit Bank Account Class as Saving & Current


As you can see, the subclass B includes all of the members of its superclass, A. This is why
subOb can access i and j and call showij( ). Also, inside sum( ), i and j can be referred to directly,
as if they were part of B. Even though A is a superclass for B, it is also a completely independent,
stand-alone class. Being a superclass for a subclass does not mean that the superclass cannot be
used by itself. Further, a subclass can be a superclass for another subclass.

The general form of a class declaration that inherits a superclass is shown here:

               class subclass-name extends superclass-name {
               // body of class
               }

You can only specify one superclass for any subclass that you create. Java does not support the
inheritance of multiple superclasses into a single subclass. (This differs from C++, in which you
can inherit multiple base classes.) You can, as stated, create a hierarchy of inheritance in which a
subclass becomes a superclass of another subclass. However, no class can be a superclass of itself .


Using super:-

Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword
super .super has two general forms. The first calls the superclass’ constructor. The second is used
to access a member of the superclass that has been hidden by a member of a subclass. Each use is
examined here.
Using super to Call Superclass Constructors
A subclass can call a constructor method defined by its superclass by use of the
following form of super:
                         super(parameter-list);
A parameter-list specifies any parameters needed by the constructor in the superclass super( )
must always be the first statement executed inside a
subclass’ constructor.
        To see how super( ) is used, consider this example

// BoxWeight now uses super to initialize its Box attributes.
class BoxWeight extends Box {

                                                                                                        19
SDTL
04: Inherit Bank Account Class as Saving & Current


double weight; // weight of box
// initialize width, height, and depth using super()
BoxWeight(double w, double h, double d, double m) {
super(w, h, d); // call superclass constructor
weight = m;
}}
Here, BoxWeight( ) calls super( ) with the parameters w, h, and d. This causes the Box( )
constructor to be called, which initializes width, height, and depth using these values.
BoxWeight no longer initializes these values itself. It only needs to initialize the value unique to
it: weight. This leaves Box free to make these values private if desired. In the preceding example,
super( ) was called with three arguments. Since constructors can be overloaded, super( ) can be
called using any form defined by the superclass. The constructor executed will be the one that
matches the arguments. For example, here is a complete implementation of BoxWeight that
provides constructors for the various ways that a box can be constructed. In each case, super( ) is
called using the appropriate arguments. Notice that width, height, and depth have been made
private within Box.


Overriding and Hiding Members
Under certain circumstances, a subclass may override non-static methods defined in the superclass
that would otherwise be inherited. When the method is invoked on an object of the subclass, it is
the new method implementation in the subclass that is executed. The overridden method in the
superclass is not inherited by the subclass, and the new method in the subclass must uphold the
following rules of method overriding:
        The new method definition must have the same method signature (i.e., method name and
        parameters) and the same return type.
        Whether parameters in the overriding method should be final is at the discretion of the
        subclass. A method's signature does not encompass the final modifier of parameters, only
        their types and order.
        The new method definition cannot narrow the accessibility of the method, but it can widen
        it. The new method definition can only specify all or none, or a subset of the exception
        classes (including their subclasses) specified in the throws clause of the overridden method
        in the super class.

                                                                                                       20
SDTL
04: Inherit Bank Account Class as Saving & Current


An instance method in a subclass cannot override a static method in the superclass. The compiler will
flag this as an error. A static method is class-specific and not part of any object, while overriding
methods are invoked on behalf of objects of the subclass. However, a static method in a subclass can
hide a static method in the superclass.
A final method cannot be overridden because the modifier final prevents method overriding. An
attempt to override a final method will result in a compile-time error. However, an abstract method
requires the non-abstract subclasses to override the method, in order to provide an implementation.


Accessibility modifier private for a method means that the method is not accessible outside the class
in which it is defined; therefore, a subclass cannot override it. However, a subclass can give its own
definition of such a method, which may have the same signature as the method in its superclass.
Overriding vs. Overloading
Method overriding should not be confused with method overloading. Method overriding requires the
same method signature (name and parameters) and the same return type. Only non-final instance
methods in the superclass that are directly accessible from the subclass are eligible for overriding.
Overloading occurs when the method names are the same, but the parameter lists differ. Therefore, to
overload methods, the parameters must differ in type, order, or number. As the return type is not a
part of the signature, having different return types is not enough to overload methods.
FAQS:
  1. Can an inner class declared inside of method access local variables of this method?
  2. What's the main difference between a Vector and an ArrayList?
  3. You can create an abstract class that contains only abstract methods. On the other hand,
      you can create an interface that declares the same methods. So can you use abstract classes
      instead of interfaces?
  4. What access level do you need to specify in the class declaration to ensure that only
      classes from the same directory can access it?
  5. When you declare a method as abstract method?
  6. Can I call a abstract method from a non abstract method
  7. What is the difference between an Abstract class and Interface in Java ? or can you
      explain when you use Abstract classes ?
  8. What is the purpose of garbage collection in Java, and when is it used?
  9. What is the purpose of finalization?
  10. What is the difference between static and non-static variables?
  11. How are this() and super() used with constructors?
  12. What are some alternatives to inheritance?
Sdtl assignment 03

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Inheritance
InheritanceInheritance
Inheritance
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - Inheritance
 
Class and object
Class and objectClass and object
Class and object
 
Unit3 java
Unit3 javaUnit3 java
Unit3 java
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
04cpp inh
04cpp inh04cpp inh
04cpp inh
 
06 inheritance
06 inheritance06 inheritance
06 inheritance
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
Inheritance polymorphism-in-java
Inheritance polymorphism-in-javaInheritance polymorphism-in-java
Inheritance polymorphism-in-java
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 

Destacado

MIS MySQL 入門
MIS MySQL 入門MIS MySQL 入門
MIS MySQL 入門均民 戴
 
Bootstrap個人網站 20141117
Bootstrap個人網站 20141117Bootstrap個人網站 20141117
Bootstrap個人網站 20141117均民 戴
 
資訊創意課程 - Create A Personal Website 1
資訊創意課程 - Create A Personal Website 1資訊創意課程 - Create A Personal Website 1
資訊創意課程 - Create A Personal Website 1均民 戴
 
JSON 和 Android 的火花
JSON 和 Android 的火花JSON 和 Android 的火花
JSON 和 Android 的火花均民 戴
 
SITCON 2014 - Regular Expression Introduce
SITCON 2014 - Regular Expression IntroduceSITCON 2014 - Regular Expression Introduce
SITCON 2014 - Regular Expression Introduce均民 戴
 
在 DigitalOcean 架設 Gitlab
在 DigitalOcean 架設 Gitlab在 DigitalOcean 架設 Gitlab
在 DigitalOcean 架設 Gitlab均民 戴
 
寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)均民 戴
 
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境均民 戴
 

Destacado (10)

MIS MySQL 入門
MIS MySQL 入門MIS MySQL 入門
MIS MySQL 入門
 
Bootstrap個人網站 20141117
Bootstrap個人網站 20141117Bootstrap個人網站 20141117
Bootstrap個人網站 20141117
 
資訊創意課程 - Create A Personal Website 1
資訊創意課程 - Create A Personal Website 1資訊創意課程 - Create A Personal Website 1
資訊創意課程 - Create A Personal Website 1
 
JSON 和 Android 的火花
JSON 和 Android 的火花JSON 和 Android 的火花
JSON 和 Android 的火花
 
Manaury ogando tejeda 14 spds-1-293
Manaury ogando tejeda  14 spds-1-293Manaury ogando tejeda  14 spds-1-293
Manaury ogando tejeda 14 spds-1-293
 
SITCON 2014 - Regular Expression Introduce
SITCON 2014 - Regular Expression IntroduceSITCON 2014 - Regular Expression Introduce
SITCON 2014 - Regular Expression Introduce
 
在 DigitalOcean 架設 Gitlab
在 DigitalOcean 架設 Gitlab在 DigitalOcean 架設 Gitlab
在 DigitalOcean 架設 Gitlab
 
寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)寫程式?那些老師沒教的事 (Git 部分節錄)
寫程式?那些老師沒教的事 (Git 部分節錄)
 
CN Unit 3
CN Unit 3 CN Unit 3
CN Unit 3
 
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
 

Similar a Sdtl assignment 03

Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceKuntal Bhowmick
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
 
Advanced programming topics asma
Advanced programming topics asmaAdvanced programming topics asma
Advanced programming topics asmaAbdullahJana
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear ASHNA nadhm
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Abid Kohistani
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceKuntal Bhowmick
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance SlidesAhsan Raja
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Akhil Mittal
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
 
Herencia
HerenciaHerencia
Herenciajaohola
 

Similar a Sdtl assignment 03 (20)

Inheritance
InheritanceInheritance
Inheritance
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritance
 
java_inheritance.pdf
java_inheritance.pdfjava_inheritance.pdf
java_inheritance.pdf
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Advanced programming topics asma
Advanced programming topics asmaAdvanced programming topics asma
Advanced programming topics asma
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Presentation 3.pdf
Presentation 3.pdfPresentation 3.pdf
Presentation 3.pdf
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritance
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance Slides
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Java basics
Java basicsJava basics
Java basics
 
Inheritance
InheritanceInheritance
Inheritance
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
Herencia
HerenciaHerencia
Herencia
 

Sdtl assignment 03

  • 1. 03: Inherit Bank Account Class as Saving & Current AIM : A class derived from Account that holds information about saving and current account also implements overrides method and print summary of saving and current account. OBJECTIVE : To expose the concepts of inheritance and overriding. THEORY Inheritance: -Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications. Using inheritance, you can create a general class that defines traits common to a set of related items. This class can then be inherited by other, more specific classes, each adding those things that are unique to it. In the terminology of Java, a class that is inherited is called a superclass. The class that does the inheriting is called a subclass. Therefore, a subclass is a specialized version of a superclass. It inherits all of the instance variables and methods defined by the superclass. Inheritance Basics: - To inherit a class, you simply incorporate the definition of one class into another by using the ‘ extends’ keyword. To see how, let’s begin with a short example. The following program creates a superclass called A and a subclass called B. Notice how the keyword extends is used to create a subclass of A. // A simple example of inheritance. // Create a superclass. class A { int i, j; void showij() { System.out.println("i and j: " + i + " " + j); }} // Create a subclass by extending class A. class B extends A { int k; void showk() { System.out.println("k: " + k);} void sum() { System.out.println("i+j+k: " + (i+j+k)); 17 SDTL
  • 2. 04: Inherit Bank Account Class as Saving & Current }} class SimpleInheritance { public static void main(String args[]) { A superOb = new A(); B subOb = new B(); // The superclass may be used by itself. superOb.i = 10; superOb.j = 20; System.out.println("Contents of superOb: "); superOb.showij(); System.out.println(); /* The subclass has access to all public members of its superclass. */ subOb.i = 7; subOb.j = 8; subOb.k = 9; System.out.println("Contents of subOb: "); subOb.showij(); subOb.showk(); System.out.println(); System.out.println("Sum of i, j and k in subOb:"); subOb.sum(); }} The output from this program is shown here: Contents of superOb: i and j: 10 20 Contents of subOb: i and j: 7 8 k: 9 Sum of i, j and k in subOb: i+j+k: 24 18 SDTL
  • 3. 04: Inherit Bank Account Class as Saving & Current As you can see, the subclass B includes all of the members of its superclass, A. This is why subOb can access i and j and call showij( ). Also, inside sum( ), i and j can be referred to directly, as if they were part of B. Even though A is a superclass for B, it is also a completely independent, stand-alone class. Being a superclass for a subclass does not mean that the superclass cannot be used by itself. Further, a subclass can be a superclass for another subclass. The general form of a class declaration that inherits a superclass is shown here: class subclass-name extends superclass-name { // body of class } You can only specify one superclass for any subclass that you create. Java does not support the inheritance of multiple superclasses into a single subclass. (This differs from C++, in which you can inherit multiple base classes.) You can, as stated, create a hierarchy of inheritance in which a subclass becomes a superclass of another subclass. However, no class can be a superclass of itself . Using super:- Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super .super has two general forms. The first calls the superclass’ constructor. The second is used to access a member of the superclass that has been hidden by a member of a subclass. Each use is examined here. Using super to Call Superclass Constructors A subclass can call a constructor method defined by its superclass by use of the following form of super: super(parameter-list); A parameter-list specifies any parameters needed by the constructor in the superclass super( ) must always be the first statement executed inside a subclass’ constructor. To see how super( ) is used, consider this example // BoxWeight now uses super to initialize its Box attributes. class BoxWeight extends Box { 19 SDTL
  • 4. 04: Inherit Bank Account Class as Saving & Current double weight; // weight of box // initialize width, height, and depth using super() BoxWeight(double w, double h, double d, double m) { super(w, h, d); // call superclass constructor weight = m; }} Here, BoxWeight( ) calls super( ) with the parameters w, h, and d. This causes the Box( ) constructor to be called, which initializes width, height, and depth using these values. BoxWeight no longer initializes these values itself. It only needs to initialize the value unique to it: weight. This leaves Box free to make these values private if desired. In the preceding example, super( ) was called with three arguments. Since constructors can be overloaded, super( ) can be called using any form defined by the superclass. The constructor executed will be the one that matches the arguments. For example, here is a complete implementation of BoxWeight that provides constructors for the various ways that a box can be constructed. In each case, super( ) is called using the appropriate arguments. Notice that width, height, and depth have been made private within Box. Overriding and Hiding Members Under certain circumstances, a subclass may override non-static methods defined in the superclass that would otherwise be inherited. When the method is invoked on an object of the subclass, it is the new method implementation in the subclass that is executed. The overridden method in the superclass is not inherited by the subclass, and the new method in the subclass must uphold the following rules of method overriding: The new method definition must have the same method signature (i.e., method name and parameters) and the same return type. Whether parameters in the overriding method should be final is at the discretion of the subclass. A method's signature does not encompass the final modifier of parameters, only their types and order. The new method definition cannot narrow the accessibility of the method, but it can widen it. The new method definition can only specify all or none, or a subset of the exception classes (including their subclasses) specified in the throws clause of the overridden method in the super class. 20 SDTL
  • 5. 04: Inherit Bank Account Class as Saving & Current An instance method in a subclass cannot override a static method in the superclass. The compiler will flag this as an error. A static method is class-specific and not part of any object, while overriding methods are invoked on behalf of objects of the subclass. However, a static method in a subclass can hide a static method in the superclass. A final method cannot be overridden because the modifier final prevents method overriding. An attempt to override a final method will result in a compile-time error. However, an abstract method requires the non-abstract subclasses to override the method, in order to provide an implementation. Accessibility modifier private for a method means that the method is not accessible outside the class in which it is defined; therefore, a subclass cannot override it. However, a subclass can give its own definition of such a method, which may have the same signature as the method in its superclass. Overriding vs. Overloading Method overriding should not be confused with method overloading. Method overriding requires the same method signature (name and parameters) and the same return type. Only non-final instance methods in the superclass that are directly accessible from the subclass are eligible for overriding. Overloading occurs when the method names are the same, but the parameter lists differ. Therefore, to overload methods, the parameters must differ in type, order, or number. As the return type is not a part of the signature, having different return types is not enough to overload methods. FAQS: 1. Can an inner class declared inside of method access local variables of this method? 2. What's the main difference between a Vector and an ArrayList? 3. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces? 4. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it? 5. When you declare a method as abstract method? 6. Can I call a abstract method from a non abstract method 7. What is the difference between an Abstract class and Interface in Java ? or can you explain when you use Abstract classes ? 8. What is the purpose of garbage collection in Java, and when is it used? 9. What is the purpose of finalization? 10. What is the difference between static and non-static variables? 11. How are this() and super() used with constructors? 12. What are some alternatives to inheritance?