GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

OO programming

Tijan Weir Englisch 57 Karten

Karten in diesem Stapel (57)

  1. 1What is a class?A specification of a set of variables (state) and methods
    (code) that are encapsulated together.
  2. 2What are instance variables?A set of zero or more variables encapsulated within a
    single class.
  3. 3what is a method?A named, parameterized block of code that is encapsulated
    within a single class.
  4. 4what is an instance?a realisation of a class
  5. 5What type of parameter passing is used in java?Pass by value
  6. 6What does this keyword do?returns an object reference to the
    instance which the current method is executing in.
  7. 7What are reference types?reference types are references to objects. When using these you are changing the references it refers to, not the object
  8. 8What are value types?Value Types are primitive values (in Java). When used, it is the data
    itself you are accessing/modifying.
    Variables of a primitive type are the only ones that use this. e.g. int
  9. 9What is the motivation for inheritance?inheritance provides a mechanism to promote reuse and extensibility.
    Code can be passed around a suited to specific needs
  10. 10What happens when a class is extended?the instance variables and methods defined in the super-class implicitly become part of the new class
  11. 11What are the names for the class being extended?base class, super class or
    the parent class
  12. 12what the name for the class inheriting from another?subclass
  13. 13Inheritance forms trees. What happens further up the tree and further down the tree?up the tree we become more generalist and abstract
    down the tree we become more specialist and domain specific
  14. 14when creating a new constructor for the subclass, what must be done?you must put super() as the first line
  15. 15What can method overriding be used for?Method overriding can be used to change the behavior by replacing a
    method in the super-class.
  16. 16What is method overloading?having the multiple of the methods of the same class and name BUT have different parameters... i.e. one may take 2 ints and one may take just 1 int
  17. 17what are the implications of polymorphism?any instance of a subclass can be treated as the super-class
  18. 18what is casting and how is it done?Casting is the process of converting a primitive variable from one type to another
    e.g. int i = 10;
    float j = (float) i;
  19. 19What are abstract classes?classes that can only be extended, never instantiated
  20. 20what are the limitations of Java inheritance polymorphism?java is a single inheritance language
  21. 21What are interfaces?like abstract classes but only methods that must be used by the subclass
    Interfaces cannot contain any instance variables.
    Interfaces cannot contain any method implementation.
    classes can have multiple interfaces
  22. 22What are implements and extend used for?implements is used for interfaces
    extends is used for classes (make a subclass)
  23. 23What are the 2 trees in inheritance?interface hierarchy
    object hierarchy
  24. 24what does toString return?Returns a humanly readable serialization of the object instance.
  25. 25what does equals() do?Tests if the instance the method is called on and that provided as a
    parameter are, by the programmers definition, equivalent
  26. 26what does clone() do?Creates and returns a duplicate copy of the current object
    instance.
  27. 27What is shallow copy cloning?when you clone(), you only clone the first instance and not everything it references i.e. other instances
  28. 28what is deep copy cloning?when you clone(), you clone any the references as well.
  29. 29whats the dangers of deep cloning()?risk of infinite cloning, if the references are circular
  30. 30What must you do to be able to clone?implements cloneable
    shallow copy: nothing more
    deep copy: override method, and clone any (or all) of the object references we are holding as instance variables.
  31. 31What is recursion?Recursion lends itself to processing where a task can be represented as a
    finite nested model of itself
  32. 32How to prevent infinite recursive loops?ensure you have a terminate case.
    ensure the problem gets smaller every time (monotonic across a state space)
    ensure that all parts of the definition eventually lead to the
    terminating case.
  33. 33What are the implications of Recursion in Java?Have a larger dynamic RAM footprint than iterative equivalents
    Footprint grows linearly with number of invocations…
    known as stack explosion
    Take longer to execute due to overheads in the JVM associated
    with method invocation, memory allocation.
  34. 34What are the 3 types of recursion?Head Recursion - The first statement in a method is recursive
    Middle / Multi Recursion - One or more arbitrary statements in a method is recursive
    Tail Recursion - The final statement in a method is recursive.
  35. 35The four principles of object orientationabstraction
    encapsulation
    inheritance
    polymorphism
  36. 36what are the four access control modifiers?public
    private
    protected
    none
  37. 37When should you write accessor and getters?Accessors - Write only if you want the variable to be visible outside the class.
    Getter - Write only if you want the variable to be mutable
  38. 38what does the final keyword do?defines total immutability
    Cannot be altered at all.
    Classes cannot be sub-classed
    Methods cannot be overridden
  39. 39what does this do: public final Person theMan = new Person(“Joe”);it means theMan can never reference another instance/object. Joe
  40. 40what are static variables?variables declared inside a class with the static modifier are unique to the class.
    Any instances of the class share the same variable – so care if this is mutable!
  41. 41Can static method,variables etc be accessed without creating an instance?yes
  42. 42What are inner classes?classes that are created inside another class.
    Public outerclass
    {
    private inncerclass { //bla bla}
    }
    can be accessed by dot notation.
    outclass.innerclass.method()
  43. 43what does Java group classes and interfaces together into?packages
  44. 44How do you add a class to a package?above class name put:
    package
    Public className
  45. 45when you add classes to package they get put in a new name space. How do you access that name space from a class outside of it?import the package first or
    package.class urVariable
    urVariable = new package.class()
  46. 46whats the naming convention for package?always use lower case for package names
    prefix package names with the (inverted!) domain name of you organization
  47. 47what are try/catch blocks and what does each part do?try { area where exception may be raise}
    catch {if exception is raised, what will be done}
  48. 48what are finally blocks of code?finally surrounds a block of code that you want to be unconditionally executed
    after the try/catch blocks… no matter what.
  49. 49what are throw semantics?declares the exceptions a method throws…
    eg Method() throws IOException
  50. 50How do you create an exception?just like a class
    Exception e = new Exception();
    then can throw it
    throw e;
  51. 51What are the good practices for exceptions?Handle exceptions as soon as possible
    Ignoring exceptions is SERIOUSLY BAD STYLE
    Always declare the exception you throw in your documentation
    Create your own (checked!) exception types
    Don't use exceptions for everyday coding
  52. 52What are generics?Generic ‘types’ are defined as classes or interfaces
    -Appended with one or more formal type parameters
  53. 53What are wildcard types?A way of talking about generics generally.
    as a parameter matches any generic instantiation of a generic type
  54. 54what are the benefits of generic classes?Extensibility with compile time type safety
  55. 55what are the generic limitations in java?Runtime Type Erasure
    Implications of Type Erasure
    Class local variables aren’t!
  56. 56What are class factories?An abstract class or interface defining a method that creates
    instances and returns object references of your base type. This is
    known as a Class Factory
  57. 57What does the Class class do?Represents a single class.

Informationen

Beschreibung
Karteikarten am OO programming, erstellt von Tijan Weir am 10/05/2017.
Erstellt von
Tijan Weir · Mai 2017
Aktualisiert
16 Mai 2017
Aufrufe
2
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck