EE219 - Semester /2009 Solutions Page 1 of 10
|
|
- Roberta Gertrude Waters
- 6 years ago
- Views:
Transcription
1 EE219 Object Oriented Programming I (2008/2009) SEMESTER 1 SOLUTIONS Q1(a) Corrected code is: #include<iostream.h> class Account protected: float balance; int actnum; ; class SavingsAccount:public Account private: float interestrate; ; public: SavingsAccount(float, int, float); virtual void display(); SavingsAccount::SavingsAccount(float abalance, int anaccnum, float irate) balance = abalance; actnum = anaccnum; interestrate = irate; void SavingsAccount::display() cout << "Balance is " << balance << endl; cout << "Act Num is " << actnum << endl; cout << "Interest Rate is " << interestrate << endl; int main(void) SavingsAccount a(10.0f, 12345, 5.0); a.display(); return 0; Errors: Line 01: #import should be #include Line 01: Missing use of standard namespace Line 05: States cannot be private in Account Line 06: Cannot initialise states in C++ Line 08: Class definition missing closing ; Line 16: Constructor cannot be virtual EE219 - Semester /2009 Solutions Page 1 of 10
2 Line 27: return type void missing from display() method Line 36: Wrong number of parameters passed to SavingsAccount constructor Line 37: Cannot access private state of SavingsAccount directly from outside class [2 marks for each point] [18 marks] Q1(b) int main(void) SavingsAccount myaccountarray[3] = SavingsAccount(100.0f,1,5.0f), SavingsAccount(200.0f,2,5.0f), SavingsAccount(300.0f,3,5.0f); SavingsAccount *ptr = &myaccountarray[0]; for(int i=0; i<3; i++) (ptr++)->display(); return 0; Alternative notation: Ptr->display() is equivalent to (*ptr).display(); [5 marks] [2 marks] [7 marks] Q2(a) #include<iostream.h> #include<string.h> class Person string name; string address; ; public: Person(string, string); virtual void display(); class Student: public Person string student_id; string programme; int year; EE219 - Semester /2009 Solutions Page 2 of 10
3 ; public: Student(Person, string, string, int); Student(string, string, string, string, int); virtual int getyear(); virtual void setyear(int); virtual void display(); Person::Person(string aname, string anaddress): name(aname), address(anaddress) void Person::display() cout << "Person Details" << endl; cout << "Name: " << name << endl; cout << "Address: " << address << endl; Student::Student(Person p, string anid, string aprogramme, int ayear): Person(p), student_id(anid), programme(aprogramme), year(ayear) Student::Student(string aname, string anaddress, string anid, string aprogramme, int ayear): Person(aName, anaddress), student_id(anid), programme(aprogramme), year(ayear) int Student::getYear() return year; void Student::setYear(int newyear) year = newyear; void Student::display() Person::display(); cout << "Student ID: " << student_id << endl; cout << "Programme: " << programme << endl; cout << "Year: " << year << endl; int main() Student s(person("john Doe", "DCU"), "12345", "Engineering", 2); s.display(); Student s2("jane Doe", "DCU", "23456", "Engineering", 3); s2.display(); s.setyear(10); cout << s.getyear() << endl; system("pause"); return 0; [2 marks for each constructor] [1 marks for each accessor/mutator] [5 marks for correct display methods] [5 marks for main] [18 marks total] EE219 - Semester /2009 Solutions Page 3 of 10
4 Q2(b) An abstract class is a class that is incomplete, in that it describes a set of operations, but is missing the actual implementation of these operations. Abstract classes: Cannot be instantiated. So, can only be used through inheritance. To make the Person class abstract we could write: virtual void display() = 0; (any method would do, even adding one) The constructor taking a Person object as a parameter would no longer be valid. You would then have to write a full implementation for display() in the child class. e.g. void Student::display() cout << Person Details << endl; cout << "Name: " << name << endl; cout << "Address: " << address << endl; cout << "Student ID: " << student_id << endl; cout << "Programme: " << programme << endl; cout << "Year: " << year << endl; Importantly, name and address would have to be specified as protected in the Person class. [7 marks] Q3(a) Polymorphism means "multiple forms". In OOP these multiple forms refer to multiple forms of the same method, where the exact same method name can be used in different classes, or the same method name can be used in the same class with slightly different parameters. There are two forms of polymorphism, over-riding and overloading. A derived class inherits its methods from the base class. It may be necessary to redefine an inherited method to provide specific behavior for a derived class - and so alter the implementation. So, over-riding is the term used to describe the situation where the same method name is called on two different objects and each object responds differently. Over-riding allows different kinds of objects that share a common behavior to be used in code that only requires that common behavior. EE219 - Semester /2009 Solutions Page 4 of 10
5 e.g. class ExampleBase virtual void display(); ; class ExampleDerived: public ExampleBase virtual void display(); ; Over-Loading is the second form of polymorphism. The same method name can be used, but the number of parameters or the types of parameters can differ, allowing the correct method to be chosen by the compiler. class Example virtual int add (int x, int y); virtual string add (String x, String y) ; [6 marks for description] [6 marks for code] [12 marks] Q3(b) Explain pass-by-value and pass-by-reference. Write a short segment of code to demonstrate the difference? 8 float addinterest(float val, float rate) 9 10 return val + (val * (rate/100)); void main() float balance = 5000; 16 float irate = 5.0; balance = addinterest(balance, irate); cout << "After interest your balance is " << balance << " Euro." << endl; 21 The previous code segment passed values to the function using pass by value. In this case you are really passing the value of the variables balance and irate, so in this case the numbers 5000 and 5.0. It is only possible to have one return value when passing by value. If we wish to have multiple return values, or wish to modify the source then we can pass by reference. EE219 - Semester /2009 Solutions Page 5 of 10
6 This example is the same as the previous example except this time we are passing by eference: Passing by reference is like passing a copy of the name of the variable to the method. 8 void addinterest(float &val, float rate) 9 10 val = val + (val * (rate/100)); void main() float balance = 5000; 16 float irate = 5.0; addinterest(balance,irate); cout << "After interest your balance is " << balance << " Euro." << endl; 21 [4 marks for each segment] [5 marks for discussion] [13 marks] Q4(a) Java does not suffer from the memory leaks like C++, due to the addition of an embedded Garbage Collector (GC) and carefully structured reference counting. The GC can be run in three ways: The system calls the GC when memory is low. The system calls the GC when the CPU is idle. The user can call the GC directly, but since the GC runs as a thread in a threaded environment, there is no guarantee that it will run immediately. [7 marks] Q4(b) A Java Interface is a way of grouping methods that describe a particular behaviour. They allow developers to reuse design and they capture similarity, independent of the class hierarchy. We can share both methods and constants using Interfaces, but there can be no states in an interface. Methods in an interface are implicitly public and abstract. Constant states in an interface are implicitly public, static and final. Interfaces differ from abstract classes in that an interface cannot have an implementation for any method, i.e. all methods are abstract. Classes can implement many interfaces, all unconstrained by a class inheritance structure. interface Demo public static final String democonst = "hello"; // public static final can be omitted // as is implicit void go(); // these methods are public and abstract void stop(); // even if public abstract is omitted class SomeClass extends Object implements Demo EE219 - Semester /2009 Solutions Page 6 of 10
7 public void go() // write implementation here public void stop() // write implementation here public class TestApp public static void main(string args[]) SomeClass c = new SomeClass(); System.out.println(SomeClass.demoConst); // will print out "hello" Q4(c) [5 marks for description] [4 marks for code] [9 marks] The life cycle of the applet has the following stages: The appletviewer loads and creates the specified class. The applet initializes itself. The applet starts running. When finished the applet is destroyed. The applet always receives an init() method first and then a start() and paint() call (Note: This may happen asynchronously! i.e. at the same time). init() - This method 'sets-up' the applet, called once when the applet is first initialized. Use this method to set up the display of the applet, set colours etc. start() - Called whenever the applet is visited, i.e. the applet starts running again. You could use this method to start up an animation that stops when the applet is minimised. This method would be called when the web browser has been restored after being minimised. stop() - Called when the applet is no longer active (e.g. minimized) paint()- This method is called whenever the appearance of the applet is required to be updated, such as when the applet is being maximized from a minimized state. The appearance needs to be updated. It is also possible for the programmer to call this method. This method does nothing by default, you must write the code. destroy() - Called when the applet is discarded. This method should perform any closing down tasks that you would wish to perform, such as closing connections to databases, etc. If we do not write one of these methods then the applet will still compile as the method will be inherited from the parent Applet class. [7 marks for discussion of lifecycle] [2 marks for correct answer with correct explanation] [9 marks] EE219 - Semester /2009 Solutions Page 7 of 10
8 Q5(a) import java.awt.*; import java.awt.event.*; import java.applet.*; public class CircleClass extends Applet implements ActionListener TextField rad_str, area_str, circ_str; float rad_val, area_val, circ_val; public void init() this.add(new Label(" Enter radius of circle: ")); rad_str = new TextField("0.0",10); this.add(rad_str); Button b = new Button("Go"); b.addactionlistener(this); this.add(b); this.add(new Label("Area: ")); area_str = new TextField("0.0",10); this.add(area_str); this.add(new Label("Circumference: ")); circ_str = new TextField("0.0", 10); this.add(circ_str); this.setsize(600,40); public void actionperformed(actionevent e) try rad_val = Float.valueOf(rad_str.getText()).floatValue(); catch(exception ex) circ_val = 2*(float)Math.PI*rad_val; circ_str.settext(float.tostring(circ_val)); area_val = (float)math.pi*rad_val*rad_val; EE219 - Semester /2009 Solutions Page 8 of 10
9 area_str.settext(float.tostring(area_val)); <html><title>question5</title> <body> <center> <applet width=500 height=100 code="circleclass.class"></applet> </center> </html> Q5(b) [3 marks for HTML page, 3 marks for layout, 4 marks for events, 6 marks for functionality, 3 mark for states etc] [19 marks] A FlowLayout arranges components left-to-right top-to-bottom, much like the "centred text" button in Microsoft Word for Windows, where each line is filled and centered until the line is full. In a flow layout form each component takes its preferred size. A GridLayout lays out the components in a rectangular grid. The container that you apply the layout to, divides the area into equal sized squares and each component that you add is sized to fit that square. E.g. new GridLayout(3,2) EE219 - Semester /2009 Solutions Page 9 of 10
10 A BorderLayout arranges a container into five regions, North, South, East, West and Center. Each region can have either one or zero components. If you do not place a component in the region then it will not be displayed. When we are adding components to a container we could write something like: [2 marks each] [6 marks] EE219 - Semester /2009 Solutions Page 10 of 10
SEMESTER ONE EXAMINATIONS SOLUTIONS 2003/2004
SEMESTER ONE EXAMINATIONS SOLUTIONS 2003/2004 MODULE: Object-Oriented Programming for Engineers EE219 COURSE: B.Eng. in Electronic Engineering B.Eng. in Telecommunications Engineering B.Eng. in Digital
More informationEE219 Object Oriented Programming I Repeat Solutions for 2005/2006
EE219 Object Oriented Programming I Repeat Solutions for 2005/2006 Q1(a) Corrected Code: #include using namespace std; class Question1 int a,b; public: Question1(); Question1(int, int); virtual
More informationEE219 Object Oriented Programming I (2007/2008) REPEAT SOLUTIONS
Q1(a) Corrected code is: EE219 Object Oriented Programming I (2007/2008) REPEAT SOLUTIONS 00 #include 01 using namespace std; 02 03 class Shape 04 05 protected: 06 float posx, posy; 07 public:
More informationEE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS
Q1(a) Corrected code is: EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS 01 #include 02 using namespace std; 03 04 class Question1 05 06 int a,b,*p; 07 08 public: 09 Question1(int
More informationEE219 Object Oriented Programming I (2006/2007) SEMESTER 1 SOLUTIONS
Q1(a) Corrected code is: #include using namespace std; class Shape protected: int x, y; public: Shape(int, int); ; EE219 Object Oriented Programming I (2006/2007) SEMESTER 1 SOLUTIONS Shape::Shape(int
More informationObject-Oriented Programming EE219 Repeat 2004/2005 Page 1 of 8
REPEAT EXAMINATIONS SOLUTIONS 2004/2005 MODULE: Object-Oriented Programming for Engineers EE219 COURSE: B.Eng. in Electronic Engineering B.Eng. in Telecommunications Engineering B.Eng. in Digital Media
More informationWeek 9. Abstract Classes
Week 9 Abstract Classes Interfaces Arrays (Assigning, Passing, Returning) Multi-dimensional Arrays Abstract Classes Suppose we have derived Square and Circle subclasses from the superclass Shape. We may
More informationAn applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a
CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled
More informationJava. GUI building with the AWT
Java GUI building with the AWT AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses the controls defined by your OS therefore
More informationJava Applet Basics. Life cycle of an applet:
Java Applet Basics Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. Applet is embedded in a HTML page using the APPLET or OBJECT tag
More informationTopic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"
More informationTopic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques
More informationPart 3: Graphical User Interface (GUI) & Java Applets
1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ
More informationS.E. Sem. III [CMPN] Object Oriented Programming Methodology
S.E. Sem. III [CMPN] Object Oriented Programming Methodology Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 80 Q.1(a) Write a program to calculate GCD of two numbers in java. [5] (A) import java.util.*;
More informationSEMESTER ONE EXAMINATIONS SOLUTIONS 2004
SEMESTER ONE EXAMINATIONS SOLUTIONS 2004 MODULE: Object-Oriented Programming for Engineers EE553 COURSE: M.Eng./Grad. Dip./Grad. Cert. in Electronic Systems M.Eng./Grad. Dip./Grad. Cert. in Telecommunications
More informationJava Programming Lecture 6
Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components
More informationCommand-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.
1 CS257 Computer Science I Kevin Sahr, PhD Lecture 14: Graphical User Interfaces Command-Line Applications 2 The programs we've explored thus far have been text-based applications A Java application is
More informationWhat is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs
What is Widget Layout? Laying Out Components Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position Main problem: what if
More informationChapter 12 Advanced GUIs and Graphics
Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program
More informationObject-oriented basics. Object Class vs object Inheritance Overloading Interface
Object-oriented basics Object Class vs object Inheritance Overloading Interface 1 The object concept Object Encapsulation abstraction Entity with state and behaviour state -> variables behaviour -> methods
More informationGUI in Java TalentHome Solutions
GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator
More informationSri Vidya College of Engineering & Technology
UNIT-V TWO MARKS QUESTION & ANSWER 1. What is the difference between the Font and FontMetrics class? Font class is used to set or retrieve the screen fonts.the Font class maps the characters of the language
More informationInheritance, and Polymorphism.
Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationUser interfaces and Swing
User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends
More informationCS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)
CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers
More informationProgramming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017
Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)
More informationPackages: Putting Classes Together
Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic
More informationRoad Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets
Java Applets Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets Introduce inheritance Introduce the applet environment html needed for applets Reading:
More informationG51PRG: Introduction to Programming Second semester Applets and graphics
G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting
More informationOutline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics
Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming
More informationResizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.
COSC 3461: Module 5B Resizing a Window Widgets II What has changed? scrollbar added menu has wrapped toolbar modified (buttons lost) 2 What is Widget Layout? Size State Transitions Recall: each widget
More informationAn array is a type of variable that is able to hold more than one piece of information under a single variable name.
Arrays An array is a type of variable that is able to hold more than one piece of information under a single variable name. Basically you are sub-dividing a memory box into many numbered slots that can
More informationPolymorphism CSCI 201 Principles of Software Development
Polymorphism CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu Program Outline USC CSCI 201L Polymorphism Based on the inheritance hierarchy, an object with a compile-time
More informationSEMESTER ONE EXAMINATIONS 2008/2009 SOLUTIONS. Object-Oriented Programming for Engineers - EE553
SEMESTER ONE EXAMINATIONS 2008/2009 SOLUTIONS MODULE: COURSE: Object-Oriented Programming for Engineers - EE553 M.Eng./Grad. Dip./Grad. Cert. in Electronic Systems M.Eng./Grad. Dip./Grad. Cert. in Telecomms.
More informationFriend Functions, Inheritance
Friend Functions, Inheritance Friend Function Private data member of a class can not be accessed by an object of another class Similarly protected data member function of a class can not be accessed by
More informationLaying Out Components. What is Widget Layout?
Laying Out Components Interior Design for GUIs What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position
More informationCSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationJohn Cowell. Essential Java Fast. How to write object oriented software for the Internet. with 64 figures. Jp Springer
John Cowell Essential Java Fast How to write object oriented software for the Internet with 64 figures Jp Springer Contents 1 WHY USE JAVA? 1 Introduction 1 What is Java? 2 Is this book for you? 2 What
More informationJava - Dates and Threads
Java - Dates and Threads Thread example Java uses threads to allow 1 event to break into another. If an action is to occur a number of times with a loop or to occur until some condition is satisfied then
More informationNote: The buy help from the TA for points will apply on this exam as well, so please read that carefully.
CS 215 Spring 2018 Lab Exam 1 Review Material: - All material for the course up through the Arrays I slides - Nothing from the slides on Functions, Array Arguments, or Implementing Functions Format: -
More informationCSCI 104 Inheritance. Mark Redekopp David Kempe
1 CSCI 104 Inheritance Mark Redekopp David Kempe 2 Files for Today $ mkdir inh $ cd inh $ wget http://ee.usc.edu/~redekopp/cs104/inh.tar $ tar xvf inh.tar $ make 3 Consider this Struct/Class Examine this
More informationConstructor - example
Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever
More informationSTRUCTURING OF PROGRAM
Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the
More informationCSCI 201L Midterm Written SOLUTION Fall % of course grade
CSCI 201L Midterm Written SOLUTION Fall 2015 10% of course grade 1. Inheritance Answer the following questions about inheritance. a. Does Java allow overloading, overriding, and redefining of methods?
More informationCHAPTER 2. Java Overview
Networks and Internet Programming (0907522) CHAPTER 2 Java Overview Instructor: Dr. Khalid A. Darabkh Objectives The objectives of this chapter are: To discuss the classes present in the java.awt package
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationComp151. Inheritance: Initialization & Substitution Principle
Comp151 Inheritance: Initialization & Substitution Principle Initializing Base Class Objects If class C is derived from class B which is in turn derived from class A, then C will contain data members of
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationInheritance and Polymorphism
Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg
More informationCSCI 201L Written Exam #1 Fall % of course grade
Final Score /15 Name SOLUTION ID Extra Credit /0.5 Lecture Section (circle one): TTh 8:00-9:20 TTh 9:30-10:50 TTh 11:00-12:20 CSCI 201L Written Exam #1 Fall 2017 15% of course grade The exam is one hour
More informationPassing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates
Lecture-4 Inheritance review. Polymorphism Virtual functions Abstract classes Passing arguments to functions by Value, pointers, refrence const member functions const arguments to a function Function overloading
More informationLecture Static Methods and Variables. Static Methods
Lecture 15.1 Static Methods and Variables Static Methods In Java it is possible to declare methods and variables to belong to a class rather than an object. This is done by declaring them to be static.
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationBuilding a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver
Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
More informationAfter a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady.
Introduction After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady. Your theory that the sun is the centre of the solar system, and the earth
More informationJava Applet & its life Cycle. By Iqtidar Ali
Java Applet & its life Cycle By Iqtidar Ali Java Applet Basic An applet is a java program that runs in a Web browser. An applet can be said as a fully functional java application. When browsing the Web,
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract
More informationThe AWT Package, Placing Components in Containers, CardLayout. Preface. Introduction
Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, Placing Components in Containers, CardLayout Java Programming, Lecture Notes # 120, Revised
More informationPolymorphism Part 1 1
Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationCSC1322 Object-Oriented Programming Concepts
CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.
More information1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B
1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these 2. How many primitive data types are there in Java? A. 5 B. 6 C. 7 D. 8 3. In Java byte, short, int and long
More informationAP CS Unit 11: Graphics and Events
AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two
More informationJava for Programmers Course (equivalent to SL 275) 36 Contact Hours
Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the
More informationComputer Science II (20073) Week 1: Review and Inheritance
Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system
More informationOOP THROUGH C++(R16) int *x; float *f; char *c;
What is pointer and how to declare it? Write the features of pointers? A pointer is a memory variable that stores the address of another variable. Pointer can have any name that is legal for other variables,
More informationModule 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani
Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2017-18 Prof. Mouna M. Naravani The Applet Class Types of Applets (Abstract Window Toolkit) Offers richer and easy to use interface than AWT. An Applet
More informationOverriding המחלקה למדעי המחשב עזאם מרעי אוניברסיטת בן-גוריון
Overriding עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון 2 Roadmap A method in a child class overrides a method in the parent class if it has the same name and type signature: Parent void method(int,float)
More informationSINGLE EVENT HANDLING
SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which
More informationCS Week 13. Jim Williams, PhD
CS 200 - Week 13 Jim Williams, PhD This Week 1. Team Lab: Instantiable Class 2. BP2 Strategy 3. Lecture: Classes as templates BP2 Strategy 1. M1: 2 of 3 milestone tests didn't require reading a file. 2.
More informationJava - Applets. public class Buttons extends Applet implements ActionListener
Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationPractical 1 Date : Statement: Write a program to find a factorial of given number by user. Program:
Practical 1 Date : Statement: Write a program to find a factorial of given number by user. Program: class Pract1 public static void main(string s[]) int n,a1; n=integer.parseint(s[0]); A a = new A(); a1
More informationDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II
DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II Year / Semester: III / V Date: 08.7.17 Duration: 45 Mins
More informationDr. Hikmat A. M. AbdelJaber
Dr. Hikmat A. M. AbdelJaber JWindow: is a window without a title bar or move controls. The program can move and resize it, but the user cannot. It has no border at all. It optionally has a parent JFrame.
More informationPOLYMORPHISM. Phone : (02668) , URL :
POLYMORPHISM POLYMORPHISM Polymorphism is the property of the same object to behave differently in different context given the same message Compile Time and Runtime Polymorphism Compile time - Function
More informationG52CPP C++ Programming Lecture 13
G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and
More informationReview. Outline. Array Pointer Object-Oriented Programming. Fall 2013 CISC2200 Yanjun Li 1. Fall 2013 CISC2200 Yanjun Li 2
Review Fall 2013 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2013 CISC2200 Yanjun Li 2 1 Array Arrays are data structures containing related data items of same type. An
More informationDUKE UNIVERSITY Department of Computer Science. Midterm Solutions
DUKE UNIVERSITY Department of Computer Science CPS 001 Fall 2001 J. Forbes Midterm Solutions PROBLEM 1 : (Quick Ones (4 points)) A. Give an example of a variable declaration. int a; B. Given that you wrote
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max
More informationCS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009
CS 349 / SE 382 Design Patterns Professor Michael Terry January 21, 2009 Today s Agenda More demos! Design patterns CS 349 / SE 382 / 2 Announcements Assignment 1 due Monday at 5PM! CS 349 / SE 382 / 3
More informationC10: Garbage Collection and Constructors
CISC 3120 C10: Garbage Collection and Constructors Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/5/2018 CUNY Brooklyn College 1 Outline Recap OOP in Java: composition &
More informationComp151. Inheritance: Initialization & Substitution Principle
Comp151 Inheritance: Initialization & Substitution Principle Initializing Base Class Objects If class C is derived from class B which is in turn derived from class A, then C will contain data members of
More information22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time: 3 Hrs.
Scheme I Sample Question Paper Program Name : Computer Engineering Program Group Program Code : CO/CM/IF/CW Semester : Third 22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time:
More informationReview. Outline. Array Pointer Object-Oriented Programming. Fall 2017 CISC2200 Yanjun Li 1. Fall 2017 CISC2200 Yanjun Li 2
Review Fall 2017 CISC2200 Yanjun Li 1 Outline Array Pointer Object-Oriented Programming Fall 2017 CISC2200 Yanjun Li 2 1 Computer Fall 2017 CISC2200 Yanjun Li 3 Array Arrays are data structures containing
More informationWhat is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1
Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 4: OO Principles - Polymorphism http://courses.cs.cornell.edu/cs2110/2018su Lecture 3 Recap 2 Good design principles.
More informationSample Examination Paper Programming and Software Development
THE UNIVERSITY OF MELBOURNE DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Sample Examination Paper 2008 433-520 Programming and Software Development Exam Duration: 2 hours Total marks for this
More informationProgramming in Java, 2e Sachin Malhotra Saurabh Choudhary
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism
More information9. APPLETS AND APPLICATIONS
9. APPLETS AND APPLICATIONS JAVA PROGRAMMING(2350703) The Applet class What is an Applet? An applet is a Java program that embedded with web content(html) and runs in a Web browser. It runs inside the
More informationIntroduction to the JAVA UI classes Advanced HCI IAT351
Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing
More informationCS 180 Fall 2006 Exam II
CS 180 Fall 2006 Exam II There are 20 multiple choice questions. Each one is worth 2 points. There are 3 programming questions worth a total of 60 points. Answer the multiple choice questions on the bubble
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationIT101. Inheritance, Encapsulation, Polymorphism and Constructors
IT101 Inheritance, Encapsulation, Polymorphism and Constructors OOP Advantages and Concepts What are OOP s claims to fame? Better suited for team development Facilitates utilizing and creating reusable
More informationThis exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.
York University AS/AK/ITEC 2610 3.0 All Sections OBJECT-ORIENTED PROGRAMMING Midterm Test Duration: 90 Minutes This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationCSC 551: Web Programming. Fall 2001
CSC 551: Web Programming Fall 2001 Java Applets! applets & HTML "default methods (init, paint, ) "APPLET & OBJECT tags, applet parameters & dimensions! graphical applets "Graphics object: drawstring, drawline,
More informationPART1: Choose the correct answer and write it on the answer sheet:
PART1: Choose the correct answer and write it on the answer sheet: (15 marks 20 minutes) 1. Which of the following is included in Java SDK? a. Java interpreter c. Java disassembler b. Java debugger d.
More information