The object-oriented paradigm is a development strategy based on the concept that systems should be built from a collection of reusable components called objects.
|
Can we define an object as object = data + methods?
Objects are defined by what they DO, not by what they contain.
Do not ask object for data, but rather for work to do over that data
An example, ATM.
In many ways, designing good programs is more challenging that writing the code itself.
Bathroom Effect.
Suppose we built houses the same way we build software...
You will need to know
What are three differences between a constructor and a method?
What is a method's signature?
a) the name of the method along with the number of its parameters.
b) the name of the method along with the number and type of its parameters.
c) the name of the method along with the number, type and order of its
parameters.
d) the name of the method, its return type and the number, type, order of its
parameters.
public void foobar() {} public void foobar(int z) {} public void foobar(int z, String str) {} public void foobar(String str, int z) {}
Examine the following code segment, find an error and fix it
int k = 1; for(int sum = 0; k ‹ 2; k++) { sum += k; } while(k ‹ 3) { sum += k; k++; }
Examine the following Java classes and predict the output
public class Scope { public static void main(String[] args) { Test t = new Test(); t.methodA(); t.methodB(); } } public class Test { private int x = 21; public Test() { x = 15; } public void methodA() { int x = 5; System.out.println( x ); System.out.println( this.x ); } public void methodB() { System.out.println( x ); x = 7; System.out.println( this.x ); } }
Can static methods call non-static methods in the same class? Explain your answer.
Examine the following code segment. What is the output if this code is compiled?
public class Static { public static void main(String[] ags) { Test obj1 = new Test(); Test obj2 = new Test(); Test obj3 = obj2; System.out.println(obj3.number); System.out.println(obj3.var); } } public class Test { public static int number = 0; public int var = 0; public Test() { number++; var++; } }
Examine the following code segment.
public class Demo { public static void main(String[] ags) { String s = "change me"; changeIt(s); System.out.println(s); } public static void changeIt(String x) { x = "changed"; } }