Docsity

CSE 1322 EXAM 3 FULL REVISION NOTES WITH OBJECT-ORIENTED PROGRAMMING AND JAVA FUNDAMENTALS, Exams of Java Programming

Toggle sidebar
bg1
CSE 1322 EXAM 3 FULL REVISION NOTES WITH
OBJECT-ORIENTED PROGRAMMING AND JAVA
FUNDAMENTALS CONCEPTS
◉ When should inheritance be used?
Answer: when classes are similar
◉ What does inheritance support?
Answer: through an extended / derived class supports code reuse.
◉ A method override occurs when two methods in the same class
have the exact same method signature. True or False?
Answer: False
◉ toString( )(Java) or ToString() (C#) is a method that is in the
Object class that is inherited by all Java / C# classes. True or False?
Answer: True
◉ When a set of methods have the same name but different
types/number of parameters in the same class, they are called:
Answer: Overloaded methods
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download CSE 1322 EXAM 3 FULL REVISION NOTES WITH OBJECT-ORIENTED PROGRAMMING AND JAVA FUNDAMENTALS and more Exams Java Programming in PDF only on Docsity!

CSE 1322 EXAM 3 FULL REVISION NOTES WITH

OBJECT-ORIENTED PROGRAMMING AND JAVA

FUNDAMENTALS CONCEPTS

◉ When should inheritance be used? Answer: when classes are similar ◉ What does inheritance support? Answer: through an extended / derived class supports code reuse. ◉ A method override occurs when two methods in the same class have the exact same method signature. True or False? Answer: False ◉ toString( )(Java) or ToString() (C#) is a method that is in the Object class that is inherited by all Java / C# classes. True or False? Answer: True ◉ When a set of methods have the same name but different types/number of parameters in the same class, they are called: Answer: Overloaded methods

◉ Abstract methods are used in defining Answer: classes that need no methods implemented ◉ he reserved word super (in Java) or base (in C#). is used call the method which is defined in Answer: the parent class ◉ A class can inherit from the methods from its classes. Answer: super, parent, abstract, or interfaces ◉ What is the goal of encapsulation? Answer: To hide the values or state of a structured an object inside a class, preventing unauthorized direct access to them ◉ Since toString() is a method that is in the Object class, any call to the toString() method refers to the toString( ) method in the Object class unless Answer: specifically overridden in the child class ◉ The unique feature of an abstract class is that Answer: a subclass that extends it doesn't need to have the abstract reserved word in its declaration.

◉ GetHashCode( ) Method Answer: Serves as the default hash function ◉ GetType( ) Method Answer: Gets the Type of the current instance ◉ MemberwiseClone( ) Method Answer: Creates a shallow copy of the current Object ◉ ReferenceEquals(Object, Object) Method Answer: Determines whether the specified Object instances are the same instance ◉ ToString( ) Method Answer: Returns a string that represents the current object ◉ clone( ) Method Answer: makes a new object with the same state as an existing object and creates and returns a copy of this object ◉ equals(Object obj) Method Answer: Indicates whether some other object is "equal to" this one

◉ getClass( ) Method Answer: Returns the runtime class of this Object ◉ hashCode( ) Method Answer: Returns a hash code value for the object ◉ notify( ) Method Answer: Wakes up a single thread that is waiting on this object's monitor ◉ notifyAll( ) Method Answer: Wakes up all threads that are waiting on this object's monitor ◉ toString( ) Method Answer: Returns a string representation of the object ◉ wait( ) Method Answer: Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object

◉ Which language should the keyword base be used? Answer: base ◉ When you see super( ), or base ( ) directly called, Answer: It's calling the parent constructor ◉ What are the four levels of visibility for this course? Answer: public, private, protected, and default ◉ Public Answer: is visible everywhere in the code ◉ Private Answer: is visible only within the class ◉ Protected Answer: is visible only within the class or child classes ◉ Default Answer: •varies by language •In general, visible to class in the same package/namespace

•Note: you do not specify this keyword in your code •Note: it is a keyword used in switch statements ◉ Access Location: Same Class Answer: Access Modifiers: public: yes protected: yes default: yes private: yes ◉ Access Location: Sub-Class of the Same Package Answer: Access Modifiers: public: yes protected: yes default: yes private: no ◉ Access Location: Another class of the same package Answer: Access Modifiers: public: yes protected: yes default: yes

◉ Declaring instance variables as private and providing getters/setters helps enforce Answer: good design ◉ A change in a parent class propagates down to child classes - Answer: good for maintenence/design ◉ Why are constructors not inherited? Answer: Class Object's default (empty) constructor does nothing, but will always be called ◉ What do programmers call multiple inheritances? Answer: "Diamond of Death" ◉ What is an interface? Answer: Very similar to an abstract class Allows unrelated classes to share common methods ◉ What are the rules of interfaces? Answer: Methods must be abstract methods (i.e. no code) Even if you don't list the word abstract or virtual

do not contain a constructor ◉ What are more rules for interfaces? Answer: Convention says to use a capital I as the first letter for the name (e.g. ITalkable) - C# You can "implement" more of this using a comma You cannot instantiate it (i.e. make an object) ◉ What is the final rule for an interface? Answer: A class that implements this has a choice:

  1. Override the methods, OR
  2. Declare itself as abstract ◉ What does GUI stand for? Answer: Graphical User Interface ◉ What is a GUI? Answer: Text is laid out in a pleasing way Users can interact with the application in ways other that just typing answers. Clicking on items on the screen, seeing graphical output. Things can be drawn in 2D or even 3D.

◉ Users interact with the GUI through: Answer: Menus, Buttons, selection lists, radio buttons (select only one), checkboxes (select many), date pickers, file choosers, labels (text strings), knobs, sliders, links, progress bars, etc. ◉ How are items positioned in a GUI? Answer: with an XY coordinate ◉ What are the coordinates of a top left corner of a GUI? Answer: (0, 0) ◉ How will colors be specified? Answer: as 3 hexadecimal values ◉ Any window is a stage, Answer: you can have multiple windows ◉ A stage can only have Answer: one Scene visible at any given time ◉ Each scene

Answer: can only be applied to a single Stage at any moment. You can however define multiple scenes ◉ Scenes typically have a Answer: layout ◉ Layouts have Answer: objects in them ◉ A very common user interaction is to Answer: present the user a form to fill out ◉ When a button is pressed in a form, Answer: an event will be fired ◉ To deal with the event, Answer: you'll need to write code ◉ What does a GridPane do? Answer: lays items out in a grid ◉ The size of the grid is determined when

Going to create "clones" of the function Usually, the clone has a smaller problem to work ◉ Requirements of Recursion Answer: Must have the recursive call Must have a terminating condition Must make progress towards terminating ◉ Base Case Answer: A recursive method can only solve the simplest problem ◉ A base case usually divides the problem into two pieces: Answer: The part it can immediately solve The remainder of the problem ◉ Recursive Technique Design Answer: First: Determine the base case, i.e. the stopping point for the recursion. It should normally be the simplest case. Second: What is the case that is just one step above it? Can it be generalized enough to fit? ◉ Common Recursion Error

Answer: Either omitting the base case or writing the recursion step incorrectly so that it does not converge on the base case will cause infinite recursion, eventually exhausting memory. This error is analogous to the problem of an infinite loop in an iterative (non-recursive) solution. ◉ Stack Overflow Answer: occurs when you recurse too many times and run out of memory. Often, it is more efficient to perform calculations via iteration (looping), but it can also be easier to express an algorithm via recursion. Recursion is especially useful for non-linear situations ◉ Recursion uses the activation stack as a Answer: "reminder" (breadcrumb) of where we've been and what remains to be done ◉ Recursion uses the activation stack as a Answer: "reminder" (breadcrumb) of where we've been and what remains to be done ◉ With non-linear problems, it is best to use: Answer: recursion

Answer: our constructors must call the base class constructor, so that it can initialize its member variables. ◉ The keyword protected: Answer: defines class members which are not visible to users of the class (those who initialize and use it), but are visible to all inheriting classes (descendants) ◉ The keyword protected internal: Answer: defines class members which are both internal, i.e. visible within the entire assembly, and protected, i.e. not visible outside the assembly, but visible to classes who inherit it (even outside the assembly) ◉ When a base class is inherited: Answer: All of its public, protected and protected internal members (methods, properties, etc.) are visible to the inheriting class. - All of its private methods, properties and member-variables are not visible to the inheriting class. - All of its internal members are visible to the inheriting class, only if the base class and the inheriting class are in the same assembly (the same Visual Studio project). ◉ Downcasting Answer: casting a superclass to a subclass

◉ A method, which can be overridden, is called Answer: virtual ◉ What is the difference between overloading and overriding methods? Answer: overloading is when there are 2 methods with the same name but different parameters but overriding is when inherited methods are being redefined in another class ◉ The class with which inherit from the parent class is referred to as either one of these: Answer: a derived class, a sub class, or child class ◉ Can you instantiate an abstract class? Answer: no ◉ What does inheritance allow? Answer: a new class to "absorb" an existing class's members ◉ How does inheritance save time? Answer: by reusing proven and debugged high-quality software ◉ UML