EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS

Size: px
Start display at page:

Download "EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS"

Transcription

1 Q1(a) Corrected code is: EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS 01 #include <iostream> 02 using namespace std; class Question int a,b,*p; public: 09 Question1(int x, int y): a(x), b(y) p = &a; 10 Question1(int x): a(x), b(0) p = &a; 11 virtual void display(); 12 virtual int getsum(); 13 virtual ~Question1(); 14 ; void Question1::display() 17 cout << "a has value:" << *p << endl; 18 cout << "b has value:" << b << endl; int Question1::getSum() return a+b; Question1::~Question1() 24 cout << "object destroyed" << endl; int main() Question1 q1(5,100), q2(20); 30 q1.display(); 31 cout << "Sum of a + b = " << q1.getsum() << endl; q2.display(); 34 cout << "Sum of a + b = " << q2.getsum() << endl; 35 return 0; 36 Line 23 a destructor cannot have a return type, not even void Line 29 q3() cannot be used as there is no default constructor anymore Line 2 should say using namespace std; as cout and endl are currently undefined Lines 8 and 9 should say &a as p is a pointer Line 24 should have around object destroyed as it is a string Line 21 should say return a+b Line 31 cannot say q1.a as it is privately accessible. Line 04 The class keyword is missing Line 13 A destructor must be virtual [18 marks] Q1(b) DCU, student, staff, technician, lecturer, name, address, id, classroom, modules, desks, blackboard, phone, university EE219 - Semester /2006 Solutions Page 1 of 9

2 Create new classes: Persons, Rooms DCU IS-A University DCU has Persons, Rooms, Classroom IS-A Room Has-a Desks, blackboard Office IS-A Room Has-A phone Student IS-A Person Student Has Modules Staff IS-A Person Technician IS-A Staff Lecturer IS-A Staff Lecturer Has Modules Person Has-A name, address, id Students should draw a diagram of these relationships. [7 marks] Q2(a) #include <iostream> #include <string> #include <stdlib.h> using namespace std; class Account float balance; int accountnumber; string owner; static int nextaccountnumber; public: Account(float, string); Account(float); Account(); ; virtual void display(); virtual Account copy(); virtual void makewithdrawal(float &); // verifies amount of withdrawal int Account::nextAccountNumber = 12345; Account::Account(float bal, string name): balance(bal), owner(name) accountnumber = nextaccountnumber++; Account::Account(float bal): balance(bal) accountnumber = nextaccountnumber++; Account::Account(): balance(0.0f) accountnumber = nextaccountnumber++; void Account::display() cout << "Account number: " << accountnumber << " has balance " << balance << " Euro\n"; void Account::makeWithdrawal(float &amt) EE219 - Semester /2006 Solutions Page 2 of 9

3 if ( amt <= balance) balance-=amt; else amt = balance; balance=0; Account Account::copy() return Account(balance, owner); int main() Account a(100.00f), b(200.00f), c; float amt = f; a.display(); b.display(); b.makewithdrawal(amt); cout << "Amount of withdrawal is " << amt << " Euro" <<endl; b.display(); c = b.copy(); c.display(); system("pause"); return 0; [2 marks for each constructor, 6 total] [2 marks for display] [3 marks for copy] [4 marks for makewithdrawal] [4 marks for main] [19 marks total] 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 Account class abstract we could write: virtual void display() = 0; (any method would do, even adding one) You would make a class abstract to impose a behaviour on the child classes. You may also wish to prevent a class from being instantiated. Yes it can. [6 marks] EE219 - Semester /2006 Solutions Page 3 of 9

4 3(a) Java has a String class for all string operations. Discuss the following: There are compareto() and equals() methods how do they differ? How do the operators +, = and == affect a String object? Strings are immutable what does this mean? What is the StringBuffer class and how does it differ from the String class? Write a short segment of code to demonstrate the use of the String and StringBuffer classes. compareto() returns an int -1 if the string is less than the compared to String, 0 if the strings are equal and 1 if the string is greater than the compare string. This would return dog is greater than cat. equals() only returns true or false true if the strings are identical + allows for us to concatenate two Strings, == calls the equals() method and = allows us to assign a new String object to the String reference. Strings cannot increase in length. When we use concatenation or any operation that appears to change the size of a String what actually happens is that a new String is created in memory and the reference is assigned to that block of memory. The StringBuffer class is mutable and can change in length. In particular it has an append() method which makes it more suitable for editing operations. 3 import java.lang.*; 4 5 public class StringTest 6 7 public static void main(string args[]) 8 9 String x = "Hello "; 10 String y = new String("World!"); String z = new String(x + y); 13 System.out.println(z); 14 System.out.println("The length of this string is " 15 + z.length() + " characters."); String c = "Cat"; 18 String d = "Dog"; 19 if (c.compareto(d)<=0) System.out.println( c + " is less than " + d); if (c.equals("cat")) System.out.println("The c object is equal to Cat"); String shout = "HELLO!"; 30 System.out.println("A bit quieter - " + shout.tolowercase()); [2 marks for each point] [8 marks] EE219 - Semester /2006 Solutions Page 4 of 9

5 3 import java.lang.*; 4 5 public class StringBufferTest 6 7 public static void main(string args[]) 8 9 String s = new String("Hello World!"); 10 StringBuffer buffer = new StringBuffer(s); buffer.insert(5, " to the"); String t = buffer.tostring(); 15 System.out.println(t); [5 marks] for implementing 5 methods [13 marks] 3(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 [6 marks] void go(); void stop(); // these methods are public and abstract // even if public abstract is omitted class SomeClass extends Object implements Demo public void go() // write implementation here public void stop() // write implementation here public class TestApp EE219 - Semester /2006 Solutions Page 5 of 9

6 public static void main(string args[]) SomeClass c = new SomeClass(); System.out.println(SomeClass.demoConst); // will print out "hello" [6 marks] [12 marks] 4(a) Java applets generally do not have a main() method. What is the lifecycle of a Java applet and what standard methods do we have to write? If we do not write one of these methods will the Applet compile? 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. [10 marks] 4(b) The JIT compiler reads the bytecode of the Java applet and converts it into native machine instructions for the intended operating system, just after the applet is loaded from the disk. This can happen on a file-by-file basis or even on a method-by-method basis - hence the name, just- EE219 - Semester /2006 Solutions Page 6 of 9

7 in-time. Once the Java applet is converted into native instructions, the application/applet then runs like it was natively compiled. The JIT compiler can, in certain cases, improve the run-time execution speed of applets by a factor of 5-10 times, while still providing portability through retaining the use of intermediate byte-code. Compiled code is kept in memory until the application terminates. [5 marks] 4(c) super - allows us to refer to states and methods of the parent class directly. So, super.display() would call the display() method, written or inherited by the parent class. If the parent class of the parent class with a display() method also had a display() method, we do not have access to that method. This super predefined variable can also be used in an unusual way to call the parent constructor from within the child constructor, provided it is used as the first line of the child constructor (just like member initialisation lists in C++). this - allows us to refer to "this object", i.e. to access states or methods for the class that the code is currently within. It allows us to pass a reference to the current object and it also allows us to access the states of the class that are currently out of scope. So, an example of super and this would be: public class TestParent protected int y=2; // example parent state public TestParent(int a) // example parent constructor y=a; public class Test extends TestParent // inheritance private int x; public Test(int a) super(a); // calls the parent constructor x = 5; public void somemethod(int x) this.x = x; // this.x refers to the state of the class super.y = 5; // sets the y state of the parent class to a value of 5. someothermethod(this); // passes the current object to the // someothermethod() method [6 marks for desc (2 x 3). 4 marks for code] [10 marks] EE219 - Semester /2006 Solutions Page 7 of 9

8 Q5(a) import java.applet.*; import java.awt.*; import java.awt.event.*; public class MouseSolution extends Applet implements MouseListener private AudioClip thesound; private Image theimage; private int x,y; public void init() this.thesound = this.getaudioclip( this.getdocumentbase(), "sound.wav" ); this.theimage = this.getimage( this.getdocumentbase(), "java.gif" ); this.addmouselistener(this); public void mousepressed(mouseevent e) public void mousereleased(mouseevent e) public void mouseentered(mouseevent e) public void mouseexited(mouseevent e) public void mouseclicked(mouseevent e) this.thesound.play(); this.x = e.getx(); this.y = e.gety(); this.repaint(); public void paint(graphics g) g.drawimage(theimage, this.x, this.y, this); <title> Image Applet Page </title> <hr> <applet code=mousesolution.class width=200 height=200> </applet> <hr> [15 marks] [2 for HTML, 4 for stages, 2 for init, 2 for events, 3 for mouseclicked, 2 for paint] Q5(b) Add a canvas class eg.. class MyCanvas extends Canvas EE219 - Semester /2006 Solutions Page 8 of 9

9 public void paint(graphics g) g.drawimage(theimage, this.x, this.y, this);22 Change the paint method in MouseSolution to: public void paint(graphics g) mycanvas.repaint(); Where mycanvas is a member stage of MouseSolution with type MyCanvas. In the init method of MouseSolution add: mycanvas = new MyCanvas(); this.add(mycanvas); mycanvas.setsize(100,100); [10 marks] [4 for MyCanvas class, 3 for state and paint, 3 for init] NB: Many correct solutions to this including inner classes, Canvas event handling etc. EE219 - Semester /2006 Solutions Page 9 of 9

EE219 Object Oriented Programming I (2007/2008) REPEAT SOLUTIONS

EE219 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 information

EE219 - Semester /2009 Solutions Page 1 of 10

EE219 - Semester /2009 Solutions Page 1 of 10 EE219 Object Oriented Programming I (2008/2009) SEMESTER 1 SOLUTIONS Q1(a) Corrected code is: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

More information

Object-Oriented Programming EE219 Repeat 2004/2005 Page 1 of 8

Object-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 information

EE219 Object Oriented Programming I (2006/2007) SEMESTER 1 SOLUTIONS

EE219 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 information

EE219 Object Oriented Programming I Repeat Solutions for 2005/2006

EE219 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 information

SEMESTER ONE EXAMINATIONS SOLUTIONS 2003/2004

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 information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)

More information

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

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

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 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 information

CSIS 10A Practice Final Exam Solutions

CSIS 10A Practice Final Exam Solutions CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!=

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Inheritance, and Polymorphism.

Inheritance, 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 information

User interfaces and Swing

User 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 information

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each CS 120 Fall 2008 Practice Final Exam v1.0m Name: Model Solution True/False Section, 20 points: 10 true/false, 2 points each Multiple Choice Section, 32 points: 8 multiple choice, 4 points each Code Tracing

More information

1. 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. 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 information

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What would

More information

Get Unique study materials from

Get Unique study materials from Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code

More information

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace

More information

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

S.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 information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. CSIS 10A PRACTICE FINAL EXAM SOLUTIONS Closed Book Closed Computer 3 Sheets of Notes Allowed MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What

More information

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application Last Time v We created our first Java application v What are the components of a basic Java application? v What GUI component did we use in the examples? v How do we write to the standard output? v An

More information

Chapter 1 GUI Applications

Chapter 1 GUI Applications Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations

More information

Lecture Static Methods and Variables. Static Methods

Lecture 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 information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;

More information

Assumptions. History

Assumptions. History Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand

More information

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner. HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all

More information

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

Road 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 information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Brief Summary of Java

Brief Summary of Java Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java

More information

CMSC 341. Nilanjan Banerjee

CMSC 341. Nilanjan Banerjee CMSC 341 Nilanjan Banerjee http://www.csee.umbc.edu/~nilanb/teaching/341/ Announcements Just when you thought Shawn was going to teach this course! On a serious note: register on Piazza I like my classes

More information

Answer1. Features of Java

Answer1. Features of Java Govt Engineering College Ajmer, Rajasthan Mid Term I (2017-18) Subject: PJ Class: 6 th Sem(IT) M.M:10 Time: 1 hr Q1) Explain the features of java and how java is different from C++. [2] Q2) Explain operators

More information

Recharge (int, int, int); //constructor declared void disply();

Recharge (int, int, int); //constructor declared void disply(); Constructor and destructors in C++ Constructor Constructor is a special member function of the class which is invoked automatically when new object is created. The purpose of constructor is to initialize

More information

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A. HAS-A Relationship Association is a weak relationship where all objects have their own lifetime and there is no ownership. For example, teacher student; doctor patient. If A uses B, then it is an aggregation,

More information

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object

More information

Lecture Static Methods and Variables. Static Methods

Lecture 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 information

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course : Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order

More information

CS/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/ 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 information

UCLA PIC 20A Java Programming

UCLA PIC 20A Java Programming UCLA PIC 20A Java Programming Instructor: Ivo Dinov, Asst. Prof. In Statistics, Neurology and Program in Computing Teaching Assistant: Yon Seo Kim, PIC University of California, Los Angeles, Summer 2002

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.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 information

Java Identifiers, Data Types & Variables

Java Identifiers, Data Types & Variables Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: 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 information

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name: Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name: Section 1 Multiple Choice Questions (40 pts total, 2 pts each): Q1: Employee is a base class and HourlyWorker is a derived class, with

More information

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes Inheritance Inheritance is the mechanism of deriving new class from old one, old class is knows as superclass and new class is known as subclass. The subclass inherits all of its instances variables and

More information

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++

More information

L4,5: Java Overview II

L4,5: Java Overview II L4,5: Java Overview II 1. METHODS Methods are defined within classes. Every method has an associated class; in other words, methods are defined only within classes, not standalone. Methods are usually

More information

Instance Members and Static Members

Instance Members and Static Members Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these

More information

Java Object Oriented Design. CSC207 Fall 2014

Java 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 information

Constructor - example

Constructor - 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 information

Introduction Of Classes ( OOPS )

Introduction Of Classes ( OOPS ) Introduction Of Classes ( OOPS ) Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.

More information

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 9: Writing Java Applets Introduction Applets are Java programs that execute within HTML pages. There are three stages to creating a working Java

More information

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

2 rd class Department of Programming. OOP with Java Programming

2 rd class Department of Programming. OOP with Java Programming 1. Structured Programming and Object-Oriented Programming During the 1970s and into the 80s, the primary software engineering methodology was structured programming. The structured programming approach

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 5 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 13, 2013 Question 1 Consider the following Java definition of a mutable string class. class MutableString private char[] chars

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Accurate study guides, High passing rate! Testhorse provides update free of charge in one year!

Accurate study guides, High passing rate! Testhorse provides update free of charge in one year! Accurate study guides, High passing rate! Testhorse provides update free of charge in one year! http://www.testhorse.com Exam : 1Z0-850 Title : Java Standard Edition 5 and 6, Certified Associate Exam Version

More information

G52CPP C++ Programming Lecture 13

G52CPP 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 information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C

More information

1 Definitions & Short Answer (5 Points Each)

1 Definitions & Short Answer (5 Points Each) Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work

More information

Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction

Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction Object Oriented Programming (OOP) is a style of programming that incorporates these 3 features: Encapsulation Polymorphism Class Interaction Class Interaction There are 3 types of class interaction. One

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I.

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I. y UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I Lab Module 7 CLASSES, INHERITANCE AND POLYMORPHISM Department of Media Interactive

More information

User-built data types Mutable and immutable data

User-built data types Mutable and immutable data Chapter 18 User-built data types Mutable and immutable data In some cases the kind of data that a program uses is not provided as a built-in data type by the language. Then a data type can be programmed:

More information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 public class Point { 2... 3 private static int numofpoints = 0; 4 5 public Point() { 6 numofpoints++; 7 } 8 9 public Point(int x, int y) { 10 this(); // calling Line 5 11 this.x

More information

OBJECT ORIENTED PROGRAMMING TYm. Allotted : 3 Hours Full Marks: 70

OBJECT ORIENTED PROGRAMMING TYm. Allotted : 3 Hours Full Marks: 70 I,.. CI/. T.cH/C8E/ODD SEM/SEM-5/CS-504D/2016-17... AiIIIII "-AmI u...iir e~ IlAULAKA ABUL KALAM AZAD UNIVERSITY TECHNOLOGY,~TBENGAL Paper Code: CS-504D OF OBJECT ORIENTED PROGRAMMING TYm. Allotted : 3

More information

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Move semantics Classes Operator overloading Making your class copyable Making your class movable Rule of all or nothing Inheritance

More information

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C

More information

Programming overview

Programming overview Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in

More information

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

More About Objects. Zheng-Liang Lu Java Programming 255 / 282 More About Objects Inheritance: passing down states and behaviors from the parents to their children. Interfaces: requiring objects for the demanding methods which are exposed to the outside world. Polymorphism

More information

Function Overloading

Function Overloading Function Overloading C++ supports writing more than one function with the same name but different argument lists How does the compiler know which one the programmer is calling? They have different signatures

More information

Packages & Random and Math Classes

Packages & Random and Math Classes Packages & Random and Math Classes Quick review of last lecture September 6, 2006 ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev Objects Classes An object

More information

Polymorphism CSCI 201 Principles of Software Development

Polymorphism 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 information

COMP-202. Objects, Part III. COMP Objects Part III, 2013 Jörg Kienzle and others

COMP-202. Objects, Part III. COMP Objects Part III, 2013 Jörg Kienzle and others COMP-202 Objects, Part III Lecture Outline Static Member Variables Parameter Passing Scopes Encapsulation Overloaded Methods Foundations of Object-Orientation 2 Static Member Variables So far, member variables

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract

More information

Java Applet & its life Cycle. By Iqtidar Ali

Java 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 information

Selected Java Topics

Selected Java Topics Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings

More information

STRUCTURING OF PROGRAM

STRUCTURING 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 information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Classes Chapter 4 Classes and Objects Data Hiding and Encapsulation Function in a Class Using Objects Static Class members Classes Class represents a group of Similar objects A class is a way to bind the

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Inheritance Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

DUBLIN CITY UNIVERSITY

DUBLIN CITY UNIVERSITY DUBLIN CITY UNIVERSITY SEMESTER ONE EXAMINATIONS 2007 MODULE: Object Oriented Programming I - EE219 COURSE: B.Eng. in Electronic Engineering B.Eng. in Information Telecommunications Engineering B.Eng.

More information

Windows and Events. created originally by Brian Bailey

Windows and Events. created originally by Brian Bailey Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating

More information

Introduction to Java

Introduction to Java Introduction to Java Module 1: Getting started, Java Basics 22/01/2010 Prepared by Chris Panayiotou for EPL 233 1 Lab Objectives o Objective: Learn how to write, compile and execute HelloWorld.java Learn

More information

Lecture-5. Miscellaneous topics Templates. W3101: Programming Languages C++ Ramana Isukapalli

Lecture-5. Miscellaneous topics Templates. W3101: Programming Languages C++ Ramana Isukapalli Lecture-5 Miscellaneous topics Templates W3101: Programming Languages C++ Miscellaneous topics Miscellaneous topics const member functions, const arguments Function overloading and function overriding

More information

Polymorphism Part 1 1

Polymorphism 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 information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract

More information

Exercise: Singleton 1

Exercise: Singleton 1 Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance

More information

Extending Classes (contd.) (Chapter 15) Questions:

Extending Classes (contd.) (Chapter 15) Questions: Extending Classes (contd.) (Chapter 15) Questions: 1 1. The following C++ program compiles without any problems. When run, it even prints out the hello called for in line (B) of main. But subsequently

More information

COMP 2355 Introduction to Systems Programming

COMP 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 information

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 26 March 23, 2016 Inheritance and Dynamic Dispatch Chapter 24 Inheritance Example public class { private int x; public () { x = 0; } public void incby(int

More information

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information