Sunday, February 9, 2020
Super Keyword Research Paper Example | Topics and Well Written Essays - 1000 words
Super Keyword - Research Paper Example However, other languages have a liberal approach, which allows redefinition of keywords for purposes. Keywords refer to identifiers or symbols which stand for functions or variables. This means that keywords have a characteristic of self evaluating and self quoting interned in the KEYWORD package. They have their application in labeling named opinions to functions, and they represent symbolic values (Savinov, 2008). Programming languages vary on the provision of keywords and library routine. For instance, some languages have provisions for keyword output or input operations, while other languages offer library routine. Languages such as Python and Basic dialect use, print, as a keyword, while Lisp and C use, format and printf, in their standard library. When a programmer applies keywords to functions or variables name, this triggers a compilation error. Most of the current editors have keywords automatically set in different text color for the purposes of indicating that they are key words. Super keywords have their definition and application in Java, where they play a crucial role during inheritance. Programmers use super keywords when accessing members of the super class. Super keywords have their application when a subclass needs to define or refer to an immediate super class. The super keyword can be invoked when a method overrides one of the super classââ¬â¢s methods. The super keyword in this case can be invoked to override the method. As a result, the super keyword in java indicates the super class of the classes in which the super keyword has recently been used (Leahy, 2011). Super keywords are also standalone statements used in calling the constructor of super classes in the base class. The super keyword has two forms. The first form calls the super class constructor, while the second form accesses members of the super class that have been hidden by members of a subclass. A super keyword can be illustrated as; Public class Super class { Public void p rintMethod () { System.out.println (ââ¬Å"printed in Superclass.â⬠); } } Purpose of the Super Keyword The super keyword can be used when referring to a hidden field. This will enable the access of hidden variable data of the original class. For instance, class A has two instance variables; float b and int a. Class B, expands to class A, and it has its own data members with similar names, (a) and (b). In this instance, class B will be hiding the variables in class A. The super keyword is used in accessing the hidden variables. This can be done by using the super.member; syntax. This gives the super keyword a function of identifying the super class of its identifiable subclass. In this case, members can take the form of an instance variable or a method (Leahy, 2012). The program will display (a) in super class 1 and (a) subclass 2. The instance variable (a) in B conceals the (a) in A, hence; super keyword allows access to (a) defined in the super class. Therefore, the super keyw ord can be used in calling methods hidden by a subclass. Another purpose of the super keyword is in calling class constructors. Super keywords are used when calling super constructors in a subclass. This is done using the super(parameter-list); syntax. The parameter list includes parameters that the constructor needs in the super class. For instance, the super keyword can be used to cite a super class constructor. The mountain bike can be considered as a subclass of a
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.