Karteikarten
CE203

Karten in diesem Stapel (43)
- 1What is Object Orientation?Creating, and manipulating OBJECTS that model things that exist in the real world
- 2What Defines a class?a group of objects, with similar properties and similar behaviour
- 3What do classes represent?Template for objects
a type of entity.
Defines this entity data(attributes)
Operations(methods)
Using a class diagram - 4What are Objects?Objects are instances of a class.
Instances of a class
They have a state: data that describes the object at that time (private attributes)
Behaviour: operations that the object can perform (methods)
Identity: a name that identifies an object - 5Primitive Data typeStores a value
- 6Object type variableStores a reference to the object
- 7Scope modifiers for TOP LEVEL CLASS What is the scope of the following ? No modifier Public PrivateNo modifier- only within own package
Public - anywhere its package is accessible
Private - not allowed - 8Scope modifiers for MEMBERS of a Top Level Class, What is the scope of the following? No Modifier Public Private ProtectedNo Modifier- access permitted from anywhere INSIDE the enclosing package
Public - access permitted BEYOND the enclosing package
Private - access is prevented from outside the class, access ONLY WITHIN the enclosing CLASS
Protected - Access is prevented from outside the class, and also sub classes. - 9InheritanceClasses inherit method and variables
Methods/Variables defined in super class
Inherited Members of the superclass can be redefined in subclass
Classes inherited using keyword EXTENDS - 10Inheritance hierarchy Generalisation SpecialisationClasses that have a "is-A" relationship
Generalisation near the top
Specialisation near the bottom - 11Super ClassClass inherited from the generalisation class
is the superclass - 12Sub ClassThe more specialised class
is the sub class - 13How do you invoke the constructor r from the superclass withing the subclass?Use the super statement
return super.tostring - 14What is an Abstract class?Contain common features of their sub classes to reduce complexity
prevent a class generating objects
Abstract classes cannot be instantiated only inherited from
Keyword - abstract, Public abstract class
Must include abstract methods - 15What is an abstract method?Provide specification for sub classes
What methods must be included
Ensures consistent behaviour within class hierarchy
Meaning different typesof classes can be stored in a common structure - 16If we wish to write a program which manipulates simple shapes, circles squares triangles etc. IF we want to change the colour of all the shapes within an array called shape, whose item type is object for (int i = 0; i < shapes.length; i++) shapes[i].setColor(Color.blue); will not workCreate a new class called Shape with a setColor method
Declare all shapes subclasses of this class, then use an array of shape objects instead of type objects.
Declare the class ABSTRACT CLASS,
so all its members are instances of one of its subclassess - 17Abstract summaryProvide specification for sub classes
Define what methods MUST be included in the subclasses
This will make sure there is a consistent behaviour within a class
The different types of class, have common structure - 18Method Overloading example with different versions of int sum (int i, int j) // version 1 {return i + j;}double sum(double e, double f)
{return e + f;}
int sum (int i, int j, int k)
{return i + j + k;} - 19sum(4,5) sum(4.5,5.5) sum(4,5,6) Will call the different versions What is this process called?Static binding
because the choice of which version of the method to use, is decided in the creation
stage. - 20Dynamic BindingDynamic binding
the decision about
which version of the method, should be used.
Is decided while the program is executing - 21PolymorphismThe ability to define methods, that work on many different types.
- 22Composition Association"Has a " or "Is part of"
- 23Specialisation Associations"Is a " or "Is a kind of"
- 24Composition HierarchyRelationship goes top to bottom,
each class is a component part of a class in the level above
Do not inherit attributes - 25InterfaceExtreme example of an abstract class
All methods are abstract
Uses keyword IMPLEMENTS
Written as
public interface myInterface {
public void method1( int param );
} - 26Interface vs abstractInterface only has public static final
Inter face cannot have any constructors
interfaces implements instead of extends
Interfaces extend other interfaces but not classes
interface methods cannot be static - 27Class declared in another classinner class
Methods of an inner class access private instance variables in the class - 28What happens if inner class is public?Refer to objects of that class outside the
class
to refer to inner class (marks) outside the student class, we use
Student.Marks
example : Student.Marks m = lisa.getMarks() - 29Java swingimport javax.swint.*;
- 30What is JFrame used for and how to add themGui must be instantiated by a JFRAME
JFrame contains:
Jpanel
Components
Buttons labels etc
JFrame frame = new Jframe(); - 31How Do you extend Jframes?Public class Greeting EXTENDSJframe
- 32What is border layoutThe default layout manager
Application has a central component,
and one on each of four borders
North
West Center East
South - 33Box layoutComponents go in a single row
/column - 34FlowLayoutComponents go in a single row
New row started if container not wide enough
Default layour for Jpanels - 35GridLayoutComponents are equal in size
and go in requested rows and columns - 36Swing hierarchically1 JFRAME
2 JPanel JPanel
3 JTextBox JLabel JButton - 37Swing How to Code

- 38Graphics Drawing

- 39Event Driven programmingAfter initialisation
the program waits for events to happen. Then responds to them
Programmer writes methods to be called when events happen - 40how to implement ActionListener interface?a class must have a public
void method called
actionPerformed, with argument
type ActionEvent - 41What to do when there are multiple buttons??Instantiate a single object for
all buttons
OR
Instantiate separate objects
for each button - 42Comparison- Single event handler objectGood for buttons with similar
functions
Uses up less memory
However can cause code to be
complicated and harder to maintain - 43Comparison Multiple event handler objectsGood for when buttons are different
although uses up more memory
but code can be simplified
Informationen
- Beschreibung
- Karteikarten am CE203, erstellt von jeff caviliar am 01/05/2020.
- Erstellt von
- jeff caviliar
- Aufrufe
- 1
- Bewertung