תרגול 12 מעקב אובייקטים 1. Our exams material : Course Syllabus : includes all the material.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

What is output line of the following C++ code? Please trace int i = 1, QP; DATA: 4, B, 3, A double credit, totCredit=0.0; double num = 0.0; string LG;
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Polymorphism. Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[]) { double.
26-Jun-15 Polymorphism. 2 Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[])
SELECTION CSC 171 FALL 2004 LECTURE 8. Sequences start end.
Class Hierarchy Discussion D. Constructor public class X { private int capacity; public X() { capacity = 16;} public X(int i) {capacity = i;} public int.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Interfaces.
Intro to OOP with Java, C. Thomas Wu
Control Structures if else do while continue break switch case return for.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
תרגול 13 חזרה 1. Exam example 8 public class Stam { private char x; public Stam() { this.x = '*'; } public Stam (char c) { this.x = c; } public Stam getStam()
JAVA—Bitwise. Compiling/Executing a Java Application Source Code Java Compiler ByteCode > Java Interpreter Machine Code >
Answers to Assignment #1 (Assignment due: Wed. Feb. 05, 2003) 1. What does the "plateform independence" mean? How is it implemented in Java? 2. Summarize.
Introduction to Java Classes and Objects. What is a class A class is description of a structure that contains both data and methods – Describes a set.
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Midterm 2 Review 1. 2 Object Oriented Programming Write a Date class. It should contain fields for day, month, year, number of months per year, and number.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 17.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Method Overloading.. Method Overloading Can two methods in a class have the same name? Two methods in a class can have the same name provided – they take.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
97-2-JAVA3 第三階段考古題說明. 1 public class EX31 { public static void main(String[] argv) { Car oldcar = new Car(); Car newcar = new Car(); oldcar.eff = 10;
Converting string to integer class StringToInt { public static void main (String arg[]) { // Assume arg[0] is the input string int result = 0, pos; int.
Department of Computer Engineering Methods Computer Programming for International Engineers.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Programming Principles Operators and Expressions.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
August 6, Operators. August 6, Arithmetic Operators.
Advanced Programming Practice Questions Advanced Programming. All slides copyright: Chetan Arora.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Lecture 3: Method Parameters
Exercise Java programming
using System; namespace Demo01 { class Program
Function Call Trace public class Newton {
مفاهیم اولیه زبان جاوا Java Basic Concepts
Instance Method Review - CIS 1068 Program Design and Abstraction
CSC240 Computer Science III
CS/ENGRD 2110 Spring 2017 Lecture 5: Local vars; Inside-out rule; constructors
null, true, and false are also reserved.
TO COMPLETE THE FOLLOWING:
An Introduction to Java – Part I, language basics
The this Reference The this reference allows an object to refer to itself That is, the this reference, used inside a method, refers to the object through.
Everything the light touches, Simba, will be yours
Operators August 6, 2009.
Unit-2 Objects and Classes
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Code Animation Examples
Example with Static Variable
Arrays of Objects // The following does NOT create memory for
Recursive GCD Demo public class Euclid {
class PrintOnetoTen { public static void main(String args[]) {
Lecture 3: Method Parameters
Java Programming with Multiple Classes
Methods and Data Passing
Scope of variables class scopeofvars {
An Example of Inheritance
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Midterm 2 Review Lecture 23.
Midterm 2 Review Lecture 23.
Presentation transcript:

תרגול 12 מעקב אובייקטים 1

Our exams material : Course Syllabus : includes all the material. Previous exams (Java language): Previous exams (C language):

1. Tracing public class X { private int num; private char c; public X() { this.num=2; this.c='A'; } public X(int n) { this.num=n; this.c='B'; } public X(int n, char ch) { this.num=n; this.c=ch; } public X(X other) { this.num=other.num; c=other.c; } public int getN() { return this.num; } public char getCh() { return this.c; } public void inc() { this.num++; this.c++; } public String toString() { String s = ""; for(int i = 0; i < this.num; i++) s = s + this.c; return s; }

public class Y extends X { private X x; public Y() { super(); x = new X(); } public Y(int n) { super(n); x = new X(); } public Y(X other) { super(); x = new X(other); } public Y(X other, int n) { super(other); x = new X(n); } public void inc() { this.x.inc(); } public X makeA() { return new X(one(this.x.getN(), this.getN()), one(this.x.getCh(), this.getCh())); } private int one(int n, int m) { if(n > m) return n; return m; } private char one(char ch1, char ch2) { if(ch1 < ch2) return ch1; return ch2; } public String toString() { return this.x.toString(); } }

public class Test51 { public static void main(String[ ] args) { X a1 = new X(3,'C'); X a2 = new X(4); Y b1 = new Y(a1); a1.inc(); System.out.println(a1); System.out.println(a2); System.out.println(b1); } What is the output?

Output EEEEE BBBB CCC

2. Tracing public class X { private static int numX = 0; private int m1; private int m2; public X(int m1, int m2) { this.m1 = m1; this.m2 = m2; this.numX++; System.out.println("X(" + m1 + "," + m2 + "),#" + numX); }

public class Y extends X { private static int numY = 0; private double db; public Y(double db, int x) { super(x,x); this.db = db; numY++; System.out.println("Y(" + db + "," + x + "),#" + numY); } public Y(double db, int x, int y) { super(x,y); this.db = db; numY++; System.out.println("Y(" + db + "," + x + "),#" + numY); }

public class Z { private static int numZ = 0; private Z aa; private X bb; public Z(Z aa, X bb) { this.aa = aa; this.bb = bb; numZ++; System.out.println("Z Constructor, #" + numZ); } public class Test52 { public static void main(String[] args) { X x1 = new X(2,3); X x2 = new Y(1.5, 6); X x3 = new Y(2.3, 8, 9); Z z4 = new Z(null, x1); Z z5 = new Z(z4, x3); } What is the output?

Output X(2,3),#1 X(6,6),#2 Y(1.5,6),#1 X(8,9),#3 Y(2.3,8),#2 Z Constructor, #1 Z Constructor, #2