Computer skills and information

Computer skills and information Contact information, map and directions, contact form, opening hours, services, ratings, photos, videos and announcements from Computer skills and information, Computer Company, rahat kot, Matta.

22/11/2022

Cv and logo expert
Contact now
03449812145

Aproaches of Software TestingHome > Software Quality > Software Engineering« PreviousNext »TutorialSoftware Engineering ...
15/06/2022

Aproaches of Software Testing
Home > Software Quality > Software Engineering
« PreviousNext »
Tutorial
Software Engineering Home
Software Process Models
Agile Process
Cleanroom Software Engineering
Requirements Engineering
Requirement Modeling
Process designing concepts
Software Architecture design
Component & Interface design
Strategies of Software Testing
Approaches of Software Testing
Project Management Concepts
Advanced Software Engineering


System testing
System testing is known as the testing behavior of the system or software according to the software requirement specification.
It is a series of various tests.
It allows to test, verify and validate the business requirement and application architecture.
The primary motive of the tests is entirely to test the computer-based system.
Following are the system tests for software-based system

1. Recovery testing
To check the recovery of the software, force the software to fail in various ways.
Reinitialization, check pointing mechanism, data recovery and restart are evaluated correctness.
2. Security testing
It checks the system protection mechanism and secure improper pe*******on.
3. Stress testing
System executes in a way which demands resources in abnormal quantity, frequency.
A variation of stress testing is known as sensitivity testing.
4. Performance testing
Performance testing is designed to test run-time performance of the system in the context of an integrated system.
It always combines with the stress testing and needs both hardware and software requirements.
5. Deployment testing
It is also known as configuration testing.
The software works in each environment in which it is to be operated.
Debugging process
Debugging process is not a testing process, but it is the result of testing.
This process starts with the test cases.
The debugging process gives two results, i.e the cause is found and corrected second is the cause is not found.
debugging process
Debugging Strategies
Debugging identifies the correct cause of error.

Following are the debugging strategies:

1. Brute force
Brute force is commonly used and least efficient method for separating the cause of software error.
This method is applied when all else fails.
2. Backtracking
Backtracking is successfully used in small programs.
The source code is traced manually till the cause is found.
3. Cause elimination
Cause elimination establishes the concept of binary partitioning.
It indicates the use of induction or deduction.
The data related to the error occurrence is arranged in separate potential cause.
Characteristics of testability
Following are the characteristics of testability:

1. Operability
If a better quality system is designed and implemented then it easier to test.
2. Observability
It is an ability to see which type of data is being tested.
Using observability it will easily identify the incorrect output.
Catch and report the internal errors automatically.
3. Controllability
If the users controlled the software properly then the testing is automated and optimized better.
4. Decomposability
The software system is constructed from independent module then tested independently.
5. Simplicity
The programs must display the functional, structural, code simplicity so that programs are easier to test.
6. Stability
Changes are rare during the testing and do not disprove existing tests.
7. Understandability
The architectural designs are well understood.
The technical documentation is quickly accessible, organized and accurate.
Attributes of 'good' test
The possibility of finding an error is high in good test.
Limited testing time and resources. There is no purpose to manage same test as another test.
A test should be used for the highest probability of uncovering the errors of a complete class.
The test must be executed separately and it should not be too simple nor too complex.
Difference between white and black box testing
White-Box Testing Black-box Testing
White-box testing known as glass-box testing. Black-box testing also called as behavioral testing.
It starts early in the testing process. It is applied in the final stages of testing.
In this testing knowledge of implementation is needed. In this testing knowledge of implementation is not needed.
White box testing is mainly done by the developer. This testing is done by the testers.
In this testing, the tester must be technically sound. In black box testing, testers may or may not be technically sound.
Various white box testing methods are:
Basic Path Testing and Control Structure Testing. Various black box testing are:
Graph-Based testing method, Equivalence partitioning, Boundary Value Analysis, Orthogonal Array Testing.
Basic Path Testing
Basic path testing is proposed by Tom McCabe.
It is a white box testing technique.
It allows the test case designer to obtain a logical complexity measure of a procedural design.
This measure guides for defining a basic set of ex*****on paths.
The examples of basic path testing are as follows:
Flow graph notation
Independent program paths
Deriving test cases
Graph matrices
Control structure testing
The control structure testing is a wide testing study and also improves the quality of white-box testing.

The examples of white-box testing is as follows:

1) Conditional testing
All the program module and the logical conditions in the program are tested in conditional testing.

2) Data flow testing
A test path of a program is selected as per the location of definitions and the uses of variables in the program.

3) Loop testing
It is a white-box testing technique. Loop testing mainly focuses on the validity of the loop constructs.

Four different classes of loops are:
1. Simple loops
2. Concatenated loops
3. Nested loops
4. Unstructured loops


« PreviousNext »


Related Topics
Software Engineering
Software Architecture and Design
Software Testing

Software Requirements EngineeringHome > Software Quality > Software Engineering« PreviousNext »TutorialSoftware Engineer...
12/04/2022

Software Requirements Engineering
Home > Software Quality > Software Engineering
« PreviousNext »
Tutorial
Software Engineering Home
Software Process Models
Agile Process
Cleanroom Software Engineering
Requirements Engineering
Requirement Modeling
Process designing concepts
Software Architecture design
Component & Interface design
Strategies of Software Testing
Approaches of Software Testing
Project Management Concepts
Advanced Software Engineering


Introduction to requirement engineering
The process of collecting the software requirement from the client then understand, evaluate and document it is called as requirement engineering.
Requirement engineering constructs a bridge for design and construction.
Requirement engineering consists of seven different tasks as follow:

1. Inception
Inception is a task where the requirement engineering asks a set of questions to establish a software process.
In this task, it understands the problem and evaluates with the proper solution.
It collaborates with the relationship between the customer and the developer.
The developer and customer decide the overall scope and the nature of the question.
2. Elicitation
Elicitation means to find the requirements from anybody.
The requirements are difficult because the following problems occur in elicitation.

Problem of scope: The customer give the unnecessary technical detail rather than clarity of the overall system objective.

Problem of understanding: Poor understanding between the customer and the developer regarding various aspect of the project like capability, limitation of the computing environment.

Problem of volatility: In this problem, the requirements change from time to time and it is difficult while developing the project.

3. Elaboration
In this task, the information taken from user during inception and elaboration and are expanded and refined in elaboration.
Its main task is developing pure model of software using functions, feature and constraints of a software.
4. Negotiation
In negotiation task, a software engineer decides the how will the project be achieved with limited business resources.
To create rough guesses of development and access the impact of the requirement on the project cost and delivery time.
5. Specification
In this task, the requirement engineer constructs a final work product.
The work product is in the form of software requirement specification.
In this task, formalize the requirement of the proposed software such as informative, functional and behavioral.
The requirement are formalize in both graphical and textual formats.
6. Validation
The work product is built as an output of the requirement engineering and that is accessed for the quality through a validation step.
The formal technical reviews from the software engineer, customer and other stakeholders helps for the primary requirements validation mechanism.
7. Requirement management
It is a set of activities that help the project team to identify, control and track the requirements and changes can be made to the requirements at any time of the ongoing project.
These tasks start with the identification and assign a unique identifier to each of the requirement.
After finalizing the requirement traceability table is developed.
The examples of traceability table are the features, sources, dependencies, subsystems and interface of the requirement.
Eliciting Requirements
Eliciting requirement helps the user for collecting the requirement

Eliciting requirement steps are as follows:

1. Collaborative requirements gathering
Gathering the requirements by conducting the meetings between developer and customer.
Fix the rules for preparation and participation.
The main motive is to identify the problem, give the solutions for the elements, negotiate the different approaches and specify the primary set of solution requirements in an environment which is valuable for achieving goal.
2. Quality Function Deployment (QFD)
In this technique, translate the customer need into the technical requirement for the software.
QFD system designs a software according to the demands of the customer.
QFD consist of three types of requirement:

Normal requirements
The objective and goal are stated for the system through the meetings with the customer.
For the customer satisfaction these requirements should be there.
Expected requirement
These requirements are implicit.
These are the basic requirement that not be clearly told by the customer, but also the customer expect that requirement.
Exciting requirements
These features are beyond the expectation of the customer.
The developer adds some additional features or unexpected feature into the software to make the customer more satisfied.
For example, the mobile phone with standard features, but the developer adds few additional functionalities like voice searching, multi-touch screen etc. then the customer more exited about that feature.
3. Usage scenarios
Till the software team does not understand how the features and function are used by the end users it is difficult to move technical activities.
To achieve above problem the software team produces a set of structure that identify the usage for the software.
This structure is called as 'Use Cases'.
4. Elicitation work product
The work product created as a result of requirement elicitation that is depending on the size of the system or product to be built.
The work product consists of a statement need, feasibility, statement scope for the system.
It also consists of a list of users participate in the requirement elicitation.

Data usage per minute by YouTube
04/02/2022

Data usage per minute by YouTube

  of computer memory
03/02/2022

of computer memory

- #  is an Operating System?-A program that acts as an intermediary between a user of a computer and the computer hardwa...
31/01/2022

- # is an Operating System?

-A program that acts as an intermediary between a user of a computer and the computer hardware
Operating system goals:
-Execute user programs and make solving user problems easier
-Make the computer system convenient to use
-Use the computer hardware in an efficient manner

*Computer System Structure
Computer system can be divided into four components
Hardware – provides basic computing
resources
CPU, memory, I/O devices
Operating system
Controls and coordinates use of hardware among various applications and users
Application programs – define the ways in which the system resources are used to solve the computing
problems of the users
Word processors, compilers, web browsers, database systems, video games
Users
People, machines, other computers
Four Components of a Computer System
System Definition

-OS is a resource allocator
-Manages all resources
-Decides between conflicting requests for efficient and fair resource use
-OS is a control program
-Controls ex*****on of programs to prevent errors and improper use of the computer
-No universally accepted definition
-Everything a vendor ships when you order an operating system” is good approximation
But varies wildly
- “The one program running at all times on the computer” is the kernel. Everything else is either a
system program (ships with the operating system) or an application program

Startup
-bootstrap program is loaded at power-up or reboot
Typically stored in ROM or EPROM, generally known as firmware
Initializes all aspects of system
Loads operating system kernel and starts ex*****on

Know about some of computerHardware - The physical parts of a computer - CPUCentral processing unit; the brain of the co...
28/01/2022

Know about some of computer

Hardware

- The physical parts of a computer -

CPU
Central processing unit; the brain of the computer; controls the other elements of the computer

Disk Drive
A peripheral device that reads and/or writes information on a disk

Hard Drive
A device (usually within the computer case) that reads and writes information, including the operating system, program files, and data files

Keyboard
A peripheral used to input data by pressing keys

Modem
A peripheral device used to connect one computer to another over a phone line

Monitor
A device used to display information visually

Mouse
A peripheral device used to point to items on a monitor

NIC
Network interface card; a board inserted in a computer that provides a physical connection to a network

Printer
A peripheral device that converts output from a computer into a printed image

Software

- Instructions executed by a computer -

Applications
Complete, self-contained programs that perform a specific function (ie. spreadsheets, databases)

Bit
A computer's most basic unit of information

Boot
The process of loading or initializing an operating system on a computer; usually occurs as soon as a computer is turned on

Browser
A program used to view World Wide Web pages, such as Netscape Navigator or Internet Explorer

Bug
A part of a program that usually causes the computer to malfunction; often remedied in patches or updates to the program

Byte
Small unit of data storage; 8 bits; usually holds one character

Click

Occurs when a user presses a button on a mouse which in turn, generates a command to the computer

Database
A large structured set of data; a file that contains numerous records that contain numerous fields

Diskette
A small flexible disk used for storing computer data

Double Click
Occurs when a user presses a button on the mouse twice in quick succession; this generates a command to the computer

Download
Transferring data from another computer to your computer

Drag
Occurs when a user points the mouse at an icon or folder, presses the button and without releasing the button, moves the icon or folder to another place on the computer where the button is released

Driver
Software program that controls a piece of hardware or a peripheral

FAQ
Frequently asked question; documents that answer questions common to a particular website or program

File
Namable unit of data storage; an element of data storage; a single sequence of bytes

Folder
A graphical representation used to organize a collection of computer files; as in the concept of a filing cabinet (computer's hard drive) with files (folders)

Freeware
Software provided at no cost to the user

Gigabyte
1,073,741,824 bytes or 1,024 megabytes; generally abbreviated GB

GUI
Graphical user interface; uses pictures and words to represent ideas, choices, functions, etc.

Icon
A small picture used to represent a file or program in a GUI interface

Internet
A network of computer networks encompassing the World Wide Web, FTP, telnet, and many other protocols

IP number
Internet protocol; a computer's unique address or number on the Internet

Kilobyte
1,024 bytes; usually abbreviated KB

Megabyte
1,048,576 bytes or 1,024 kilobytes; enough storage to approximately equal a 600 page paperback book; generally abbreviated Mb

Memory
Any device that holds computer data

Menu
A list of operations available to the user of a program

Network
A collection of computers that are connected

Peripheral
Any of a number of hardware devices connected to a CPU

RAM
Random access memory; the type of storage that changes; when the computer is turned off, the RAM memory is erased

ROM
Read-only memory; the type of storage that is not changed even when the computer is turned off

Scroll Bar
Allows the user to control which portion of the document is visible in the window; available either horizontally or vertically or both

Shareware
Software provided at a minimal cost to users who are on their honor to send in payment to the programmer

Spreadsheet
A program arranged in rows and columns that manipulates numbers

Tool Bar
A graphical representation of program activities; a row of icons used to perform tasks in a program

URL
Uniform resource locator; the address of a site on the World Wide Web; a standard way of locating objects on the Internet

Virus
A deliberately harmful computer program designed to create annoying glitches or destroy data

Window
A screen in a software program that permits the user to view several programs at one time

Word Processor
A program that allows the user to create primarily text documents

What is a Solid-State Drive (SSD)?A solid-state drive (SSD) is a new generation of storage device used in computers. SSD...
26/01/2022

What is a Solid-State Drive (SSD)?

A solid-state drive (SSD) is a new generation of storage device used in computers. SSDs use flash-based memory, which is much faster than a traditional mechanical hard disk. Upgrading to an SSD is one of the best ways to speed up your computer. Learn how SSDs work and how to keep them optimized with a specialized performance-boosting tool.

26/01/2022
  Development Life  Cycle  (SDLC)==========================~>Systems development is systematic process which includes ph...
25/01/2022

Development Life Cycle (SDLC)
==========================
~>Systems development is systematic process which includes phases such as planning, analysis, design, deployment, and maintenance. Here, in this tutorial, we will primarily focus on −

-Systems analysis
-Systems design

*Systems Analysis

-It is a process of collecting and interpreting facts, identifying the problems, and decomposition of a system into its components.
System analysis is conducted for the purpose of studying a system or its parts in order to identify its objectives. It is a problem solving technique that improves the system and ensures that all the components of the system work efficiently to accomplish their purpose.
Analysis specifies what the system should do.

*Systems Design

-It is a process of planning a new business system or replacing an existing system by defining its components or modules to satisfy the specific requirements. Before planning, you need to understand the old system thoroughly and determine how computers can best be used in order to operate efficiently.
System Design focuses on how to accomplish the objective of the system.
System Analysis and Design (SAD) mainly focuses on:−

-Systems
-Processes
-Technology
=>What is a System?
The word System is derived from Greek word Systema, which means an organized relationship between any set of components to achieve some common cause or objective.
-A system is “an orderly grouping of interdependent components linked together according to a plan to achieve a specific goal.”

=>Constraints of a System
A system must have three basic constraints:−

-A system must have some structure and behavior which is designed to achieve a predefined objective.

-Interconnectivity and interdependence must exist among the system components.
-The objectives of the organization have a higher priority than the objectives of its subsystems.

For example, traffic management system, payroll system, automatic library system, human resources information system.

*Properties of a System

-A system has the following properties −

*Organization
Organization implies structure and order. It is the arrangement of components that helps to achieve predetermined objectives.

*Interaction
It is defined by the manner in which the components operate with each other.

For example, in an organization, purchasing department must interact with production department and payroll with personnel department.

*Interdependence
Interdependence means how the components of a system depend on one another. For proper functioning, the components are coordinated and linked together according to a specified plan. The output of one subsystem is the required by other subsystem as input.

*Integration
Integration is concerned with how a system components are connected together. It means that the parts of the system work together within the system even if each part performs a unique function.

*Central Objective
The objective of system must be central. It may be real or stated. It is not uncommon for an organization to state an objective and operate to achieve another.

The users must know the main objective of a computer application early in the analysis for a successful design and conversion.

of a System
The following diagram shows the elements of a system −

i) Outputs and Inputs
The main aim of a system is to produce an output which is useful for its user.
Inputs are the information that enters into the system for processing.
Output is the outcome of processing.

ii) Processor(s)
The processor is the element of a system that involves the actual transformation of input into output.

It is the operational component of a system. Processors may modify the input either totally or partially, depending on the output specification.

As the output specifications change, so does the processing. In some cases, input is also modified to enable the processor for handling the transformation.

iii) Control
The control element guides the system.
It is the decision–making subsystem that controls the pattern of activities governing input, processing, and output.
The behavior of a computer System is controlled by the Operating System and software. In order to keep system in balance, what and how much input is needed is determined by Output Specifications.

iv) Feedback
Feedback provides the control in a dynamic system.
Positive feedback is routine in nature that encourages the performance of the system.

Negative feedback is informational in nature that provides the controller with information for action.

v) Environment
The environment is the “supersystem” within which an organization operates.
It is the source of external elements that strike on the system.

It determines how a system must function. For example, vendors and competitors of organization’s environment, may provide constraints that affect the actual performance of the business.

vi) Boundaries and Interface
A system should be defined by its boundaries. Boundaries are the limits that identify its components, processes, and interrelationship when it interfaces with another system.
Each system has boundaries that determine its sphere of influence and control.
The knowledge of the boundaries of a given system is crucial in determining the nature of its interface with other systems for successful design.

# of Systems
The systems can be divided into the following types:−

1) Physical or Abstract Systems
Physical systems are tangible entities. We can touch and feel them.

Physical System may be static or dynamic in nature. For example, desks and chairs are the physical parts of computer center which are static. A programmed computer is a dynamic system in which programs, data, and applications can change according to the user's needs.

Abstract systems are non-physical entities or conceptual that may be formulas, representation or model of a real system.

2) Open or Closed Systems
An open system must interact with its environment. It receives inputs from and delivers outputs to the outside of the system. For example, an information system which must adapt to the changing environmental conditions.

A closed system does not interact with its environment. It is isolated from environmental influences. A completely closed system is rare in reality.

3) Adaptive and Non Adaptive System
Adaptive System responds to the change in the environment in a way to improve their performance and to survive. For example, human beings, animals.

Non Adaptive System is the system which does not respond to the environment. For example, machines.

4) Permanent or Temporary System
Permanent System persists for long time. For example, business policies.

Temporary System is made for specified time and after that they are demolished. For example, A DJ system is set up for a program and it is dissembled after the program.

5) Natural and Manufactured System
Natural systems are created by the nature. For example, Solar system, seasonal system.

Manufactured System is the man-made system. For example, Rockets, dams, trains.

6) Deterministic or Probabilistic System
Deterministic system operates in a predictable manner and the interaction between system components is known with certainty. For example, two molecules of hydrogen and one molecule of oxygen makes water.

Probabilistic System shows uncertain behavior. The exact output is not known. For example, Weather forecasting, mail delivery.

7) Social, Human-Machine, Machine System
Social System is made up of people. For example, social clubs, societies.

In Human-Machine System, both human and machines are involved to perform a particular task. For example, Computer programming.

Machine System is where human interference is neglected. All the tasks are performed by the machine. For example, an autonomous robot.

8) Man–Made Information Systems
It is an interconnected set of information resources to manage data for particular organization, under Direct Management Control (DMC).

This system includes hardware, software, communication, data, and application for producing information according to the need of an organization.

Man-made information systems are divided into three types −

Formal Information System − It is based on the flow of information in the form of memos, instructions, etc., from top level to lower levels of management.

Informal Information System − This is employee based system which solves the day to day work related problems.

Computer Based System − This system is directly dependent on the computer for managing business applications. For example, automatic library system, railway reservation system, banking system, etc.

# Models

1) Schematic Models
A schematic model is a 2-D chart that shows system elements and their linkages.

Different arrows are used to show information flow, material flow, and information feedback.

2) Flow System Models
A flow system model shows the orderly flow of the material, energy, and information that hold the system together.

Program Evaluation and Review Technique (PERT), for example, is used to abstract a real world system in model form.

3) Static System Models
They represent one pair of relationships such as activity–time or cost–quantity.

The Gantt chart, for example, gives a static picture of an activity-time relationship.

4) Dynamic System Models
Business organizations are dynamic systems. A dynamic model approximates the type of organization or application that analysts deal with.

It shows an ongoing, constantly changing status of the system. It consists of −

Inputs that enter the system

The processor through which transformation takes place

The program(s) required for processing

The output(s) that result from processing.

*Categories of Information

There are three categories of information related to managerial levels and the decision managers make.

-Strategic Information
This information is required by topmost management for long range planning policies for next few years. For example, trends in revenues, financial investment, and human resources, and population growth.
This type of information is achieved with the aid of Decision Support System (DSS).

-Managerial Information
This type of Information is required by middle management for short and intermediate range planning which is in terms of months. For example, sales analysis, cash flow projection, and annual financial statements.

It is achieved with the aid of Management Information Systems (MIS).

-Operational information
This type of information is required by low management for daily and short term planning to enforce day-to-day operational activities. For example, keeping employee attendance records, overdue purchase orders, and current stocks available.
It is achieved with the aid of Data Processing Systems (DPS).

 # Inheritance in Java።።።።።።።።።።።።።።።።።።~>Inheritance can be defined as the process where one class acquires the propert...
23/01/2022

# Inheritance in Java
።።።።።።።።።።።።።።።።።።
~>Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order.
The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class).

**Extends Keyword
-extends is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword.

Syntax

class Super {
.....
.....
}
class Sub extends Super {
.....
.....
}
Sample Code
Following is an example demonstrating Java inheritance. In this example, you can observe two classes namely Calculation and My_Calculation.

Using extends keyword, the My_Calculation inherits the methods addition() and Subtraction() of Calculation class.

Copy and paste the following program in a file with name My_Calculation.java

Example

Live Demo
class Calculation {
int z;

public void addition(int x, int y) {
z = x + y;
System.out.println("The sum of the given numbers:"+z);
}

public void Subtraction(int x, int y) {
z = x - y;
System.out.println("The difference between the given numbers:"+z);
}
}

public class My_Calculation extends Calculation {
public void multiplication(int x, int y) {
z = x * y;
System.out.println("The product of the given numbers:"+z);
}

public static void main(String args[]) {
int a = 20, b = 10;
My_Calculation demo = new My_Calculation();
demo.addition(a, b);
demo.Subtraction(a, b);
demo.multiplication(a, b);
}
}
Compile and execute the above code as shown below.

javac My_Calculation.java
java My_Calculation
After executing the program, it will produce the following result −

Output

The sum of the given numbers:30
The difference between the given numbers:10
The product of the given numbers:200
In the given program, when an object to My_Calculation class is created, a copy of the contents of the superclass is made within it. That is why, using the object of the subclass you can access the members of a superclass.
The Superclass reference variable can hold the subclass object, but using that variable you can access only the members of the superclass, so to access the members of both classes it is recommended to always create reference variable to the subclass.
If you consider the above program, you can instantiate the class as given below. But using the superclass reference variable ( cal in this case) you cannot call the method multiplication(), which belongs to the subclass My_Calculation.

Calculation demo = new My_Calculation();
demo.addition(a, b);
demo.Subtraction(a, b);
Note − A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.

**The super keyword
-The super keyword is similar to this keyword. Following are the scenarios where the super keyword is used.
It is used to differentiate the members of superclass from the members of subclass, if they have same names.
It is used to invoke the superclass constructor from subclass.
Differentiating the Members
If a class is inheriting the properties of another class. And if the members of the superclass have the names same as the sub class, to differentiate these variables we use super keyword as shown below.

super.variable
super.method();
Sample Code
This section provides you a program that demonstrates the usage of the super keyword.
In the given program, you have two classes namely Sub_class and Super_class, both have a method named display() with different implementations, and a variable named num with different values. We are invoking display() method of both classes and printing the value of the variable num of both classes. Here you can observe that we have used super keyword to differentiate the members of superclass from subclass.
Copy and paste the program in a file with name Sub_class.java.

Example

Live Demo
class Super_class {
int num = 20;

// display method of superclass
public void display() {
System.out.println("This is the display method of superclass");
}
}

public class Sub_class extends Super_class {
int num = 10;

// display method of sub class
public void display() {
System.out.println("This is the display method of subclass");
}

public void my_method() {
// Instantiating subclass
Sub_class sub = new Sub_class();

// Invoking the display() method of sub class
sub.display();

// Invoking the display() method of superclass
super.display();

// printing the value of variable num of subclass
System.out.println("value of the variable named num in sub class:"+ sub.num);

// printing the value of variable num of superclass
System.out.println("value of the variable named num in super class:"+ super.num);
}

public static void main(String args[]) {
Sub_class obj = new Sub_class();
obj.my_method();
}
}
Compile and execute the above code using the following syntax.

javac Super_Demo
java Super
On executing the program, you will get the following result −

Output

This is the display method of subclass
This is the display method of superclass
value of the variable named num in sub class:10
value of the variable named num in super class:20
Invoking Superclass Constructor
If a class is inheriting the properties of another class, the subclass automatically acquires the default constructor of the superclass. But if you want to call a parameterized constructor of the superclass, you need to use the super keyword as shown below.

super(values);
Sample Code
The program given in this section demonstrates how to use the super keyword to invoke the parametrized constructor of the superclass. This program contains a superclass and a subclass, where the superclass contains a parameterized constructor which accepts a integer value, and we used the super keyword to invoke the parameterized constructor of the superclass.
Copy and paste the following program in a file with the name Subclass.java

Example

Live Demo
class Superclass {
int age;

Superclass(int age) {
this.age = age;
}

public void getAge() {
System.out.println("The value of the variable named age in super class is: " +age);
}
}

public class Subclass extends Superclass {
Subclass(int age) {
super(age);
}

public static void main(String args[]) {
Subclass s = new Subclass(24);
s.getAge();
}
}
Compile and execute the above code using the following syntax.

javac Subclass
java Subclass
On executing the program, you will get the following result −

Output

The value of the variable named age in super class is: 24
IS-A Relationship
IS-A is a way of saying: This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance.

public class Animal {
}

public class Mammal extends Animal {
}

public class Reptile extends Animal {
}

public class Dog extends Mammal {
}
Now, based on the above example, in Object-Oriented terms, the following are true:-
Animal is the superclass of Mammal class.
Animal is the superclass of Reptile class.
Mammal and Reptile are subclasses of Animal class.
Dog is the subclass of both Mammal and Animal classes.
Now, if we consider the IS-A relationship, we can say:
Mammal IS-A Animal
Reptile IS-A Animal
Dog IS-A Mammal
Hence: Dog IS-A Animal as well
With the use of the extends keyword, the subclasses will be able to inherit all the properties of the superclass except for the private properties of the superclass.
We can assure that Mammal is actually an Animal with the use of the instance operator.
Example

Live Demo
class Animal {
}

class Mammal extends Animal {
}

class Reptile extends Animal {
}

public class Dog extends Mammal {

public static void main(String args[]) {
Animal a = new Animal();
Mammal m = new Mammal();
Dog d = new Dog();

System.out.println(m instanceof Animal);
System.out.println(d instanceof Mammal);
System.out.println(d instanceof Animal);
}
}
This will produce the following result −

Output

true
true
true
Since we have a good understanding of the extends keyword, let us look into how the implements keyword is used to get the IS-A relationship.

Generally, the implements keyword is used with classes to inherit the properties of an interface. Interfaces can never be extended by a class.

Example

public interface Animal {
}

public class Mammal implements Animal {
}

public class Dog extends Mammal {
}
The instanceof Keyword
Let us use the instanceof operator to check determine whether Mammal is actually an Animal, and dog is actually an Animal.

Example

Live Demo
interface Animal{}
class Mammal implements Animal{}

public class Dog extends Mammal {

public static void main(String args[]) {
Mammal m = new Mammal();
Dog d = new Dog();

System.out.println(m instanceof Animal);
System.out.println(d instanceof Mammal);
System.out.println(d instanceof Animal);
}
}
This will produce the following result −

Output

true
true
true
HAS-A relationship
-These relationships are mainly based on the usage. This determines whether a certain class HAS-A certain thing. This relationship helps to reduce duplication of code as well as bugs.
Example

public class Vehicle{}
public class Speed{}

public class Van extends Vehicle {
private Speed sp;
}
This shows that class Van HAS-A Speed. By having a separate class for Speed, we do not have to put the entire code that belongs to speed inside the Van class, which makes it possible to reuse the Speed class in multiple applications.
In Object-Oriented feature, the users do not need to bother about which object is doing the real work. To achieve this, the Van class hides the implementation details from the users of the Van class. So, basically what happens is the users would ask the Van class to do a certain action and the Van class will either do the work by itself or ask another class to perform the action.

**Types of Inheritance

There are various types of inheritance as demonstrated below.
A very important fact to remember is that Java does not support multiple inheritance. This means that a class cannot extend more than one class. Therefore following is illegal −

Example

public class extends Animal, Mammal{}
However, a class can implement one or more interfaces, which has helped Java get rid of the impossibility of multiple inheritance.

Address

Rahat Kot
Matta

Website

Alerts

Be the first to know and let us send you an email when Computer skills and information posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Share