Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the.

Similar presentations


Presentation on theme: "CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the."— Presentation transcript:

1 CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the methods that manipulate it into a single object. In particular, it refers to the ability of an object to hide particular data and methods from other objects, exposing them only through specified methods that are marked with the “public” keyword. Define/Explain inheritance. In object-oriented programming, inheritance is where a class automatically can be made to have characteristics of another class. That is, a sub-class will inherit variables and methods from a super-class that is indicated using the “extends” keyword. Objects of a particular sub-class can be treated as members of a common super-class Define/Explain polymorphism. In object-oriented programming, polymorphism is the ability of different objects to respond to the same message, each in a different way. Polymorphism occurs when we are referring to the sub-class as a member of its super-class. If there is a method or variable in the sub-class which overrides a method or variable in its super-class, then the method or variable of the sub-class is used.

2 CS 5JA Introduction to Java Pop quiz pt. 2 Give an example of where we would use the “this” keyword. The “this” keyword lets an object refer to itself. It is often be used when calling invoking a method where we want to pass in the entire object as an argument. It is also used to specify the global instance variable when a there is another local variable with the same name. This regularly happens in constructors when we want to set the instance variable to the local variable that gets passed in as an argument: int num; public MyClass(int num) { this.num = num; }

3 CS 5JA Introduction to Java Pop quiz pt. 3 When is the “abstract” keyword used? The abstract keyword is used when we want to force particular variables to be defined or methods to be implemented in a sub-class. When a class has abstract variables or methods, then the class itself must be abstract– which means that it can not be instantiated. However, any sub-classes that extend the abstract super-class will automatically inherit all the non-abstract variables and methods. Additionally, they will be required to implement the abstract variables and methods.

4 CS 5JA Introduction to Java Pop quiz pt. 3 abstract class MySuperClass //cannot be instantiated { public abstract int num1; int num2 = 373; public abstract void printNums(); public void printNum2() {System.out.println(“num2 = “ + num2); } public class MySubClass1 extends MySuperClass //must implement abstract stuff from the super-class { int num1 = 7; //implenents abstract variable public void printNums() //implements abstract method { //can refer to super-class’s variables as well. System.out.println(“num1 = “ + num1 + “ num2 = “ + num2); //can refer to super-class’s methods as well. printNum2(); }

5 CS 5JA Introduction to Java Pop Quiz pt 4 What does the “has-a” relationship between objects signify? An object may be composed in part out of other objects. For example, a bicycle object “has a” crank, a chain, a handle-bar, a frame, a seat, gears, etc. What does the “is-a” relationship between objects signify? An object often “is-a” type of object as well. For example, you might want to specify that a Triangle is a type of TwoDimensionalShape. This relationship is defined with inheritance using the “extends” keyword

6 CS 5JA Introduction to Java Pop Quiz pt 5 What does the “static” keyword refer to? If a variable or method in a class is defined as static, then it means that the variable or method will be the same for all instantiations of objects of that class. Moreover, the method or variable exists and can be used even if no objects are instantiated at all. A static method can not refer to object instance variables or methods (ie, non-static methods or variables). However, a non-static method can refer to static methods and variables. What does the “final” keyword refer to? A final variable is a non-variable variable– also known as a “constant”. Once a final variable is created in cannot be changed.

7 CS 5JA Introduction to Java On the test Questions that make sure you understand the definitions of common terms & concepts: object, class, inheritance, polymorphism, array, List, constructor, etc. Questions that make sure you understand basic syntax: looping through an multi-dimensional array, using a switch statement, looping through a List and doing actions based on the value in the List, order of operations, method signatures, scope of variables, etc Questions that show you know how to think about organizing your code into different classes and methods, how to model a problem. Questions that make sure you can debug obvious errors. Maybe some tougher extra-credit problems. The test will take 1 hour.


Download ppt "CS 5JA Introduction to Java Pop Quiz Define/Explain encapsulation. In object-oriented programming, encapsulation refers to the grouping of data and the."

Similar presentations


Ads by Google