CCEA A-Level Software Systems Development CL4
Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures
Exception Handling and Managing Input and Output
Testing an Object Oriented Application
Graphical User Interface Objects and Events
Multiple Forms and Linking to Files
Designing, Testing and Evaluating an Event Driven Application
Reasons for Systems Development and Systems Methodologies
Managing Projects
Testing Strategies
Database Concepts and Entity Relationship Modelling
Normalisation and Structured Query Language
Project Management and the Systems Approach in Practice
Defining Requirements and Documenting the Design
Building a Desktop Solution with a Database
Testing and Evaluating the Solution
Defining Data: Types, Variables and Classes
Type casting and conversion
- 3 things to know
- AS Unit 1
Overview
Type casting and lost in a narrowing conversion.
What you need to know
Answer each one before you reveal it.
How does implicit widening conversion differ from explicit narrowing conversion?
What value is stored by double d = 7 / 2;, and why?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is type casting?
Model answer
Type casting is the conversion of a value from one data type to another so that the value can be stored in, or combined with, a variable of the second type.
- 2
How does implicit widening conversion differ from explicit narrowing conversion?
Model answer
A widening conversion moves a value into a larger type and is performed automatically because nothing can be lost, whereas a narrowing conversion moves a value into a smaller type and must be written by the programmer because information may be lost.
- 3
Why does Java convert an int to a double automatically, but refuse to convert a double to an int without a cast?
Model answer
Every int value fits exactly in a double, so the widening conversion is safe, whereas a double carries a fractional part and a far larger range, so converting to an int would silently discard information.
- 4
What value does x hold after int x = (int) 9.99;, and why?
Model answer
The value of x is 9, because a cast from a real type to an integer type truncates towards zero and discards the fractional part rather than rounding.
- 5
What value is stored by double d = 7 / 2;, and why?
Model answer
The value stored is 3.0, because both operands are integers so integer division is performed first, giving 3, and only then is that result widened to a double.
- 6
What value is stored by double d = 7 / 2.0;, and why?
Model answer
The value stored is 3.5, because one operand is a double, so the integer 7 is promoted to a double and real division is carried out.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Defining Data: Types, Variables and Classes, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.