Answer ALL Questions. Each Question carries ONE Mark.

Similar documents
Exercise 1: Class Employee: public class Employee { private String firstname; private String lastname; private double monthlysalary;

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Inheritance and Polymorphism

Banaras Hindu University

Ch 7 Designing Java Classes & Class structure. Methods: constructors, getters, setters, other e.g. getfirstname(), setfirstname(), equals()

Introduction to Classes and Objects

Java Object Oriented Design. CSC207 Fall 2014

WEEK 13 EXAMPLES: POLYMORPHISM

INTERFACE WHY INTERFACE

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

SSE3052: Embedded Systems Practice

Inf1-OP. Classes with Stuff in Common. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein.

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Programming II (CS300)

Ch 7 Designing Java Classes & Class structure

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Inf1-OP. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. March 12, School of Informatics

1.00 Lecture 13. Inheritance

Encapsulation. Inf1-OOP. Getters and Setters. Encapsulation Again. Inheritance Encapsulation and Inheritance. The Object Superclass

Inf1-OOP. Inheritance and Interfaces. Ewan Klein, Perdita Stevens. January 12, School of Informatics

Introduction to Classes and Objects

Introduction to Programming

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters)

CS141 Programming Assignment #4

Create a Java project named week9

CS 201, Fall 2016 Sep 28th Exam 1

Classes. Classes as Code Libraries. Classes as Data Structures

OVERRIDING. 7/11/2015 Budditha Hettige 82

Exam Duration: 2hrs and 30min Software Design

F I N A L E X A M I N A T I O N

Chapter 6 Introduction to Defining Classes

Object Oriented Programming. Java-Lecture 11 Polymorphism

Principles of Object Oriented Programming. Lecture 4

Introduction to Java. Handout-1d. cs402 - Spring

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

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

Programming II (CS300)

Chapter 5 Object-Oriented Programming

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Lecture 7: Classes and Objects CS2301

More About Classes CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario

BBM 102 Introduction to Programming II Spring Inheritance

Java for Non Majors Spring 2018

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

PROGRAMMING FUNDAMENTALS

Arrays Classes & Methods, Inheritance

CMSC 132: Object-Oriented Programming II

Object Oriented Programming (II)

Introduction to Programming Using Java (98-388)

Questions Answer Key Questions Answer Key Questions Answer Key

JAVA MOCK TEST JAVA MOCK TEST II

Programming in the Large II: Objects and Classes (Part 2)

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

CST242 Object-Oriented Programming Page 1

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Chapter 14 Abstract Classes and Interfaces

Final Examination Semester 3 / Year 2012

CONSTRUCTOR & Description. String() This initializes a newly created String object so that it represents an empty character sequence.

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

Using Java reflection to reduce Code and Development time in DFS

Use the scantron sheet to enter the answer to questions (pages 1-6)

CS-202 Introduction to Object Oriented Programming

CIS 110: Introduction to Computer Programming

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

2. The object-oriented paradigm

Java and OOP. Part 3 Extending classes. OOP in Java : W. Milner 2005 : Slide 1

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Weak Entity Sets. A weak entity is an entity that cannot exist in a database unless another type of entity also exists in that database.

Cloning Enums. Cloning and Enums BIU OOP

What are the characteristics of Object Oriented programming language?

OOP in Java Review. CS356 Object-Oriented Design and Programming October 1, 2014

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Computer Programming Inheritance 10 th Lecture

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Full file at Chapter 2 - Inheritance and Exception Handling

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Inheritance Introduction. 9.1 Introduction 361

第三章习题答案 // include definition of class GradeBook from GradeBook.h #include "GradeBook.h"

Software and Programming 1

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

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

The Java language has a wide variety of modifiers, including the following:

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A

Lab05: Inheritance and polymorphism

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes

CH. 2 OBJECT-ORIENTED PROGRAMMING

Recitation 3 Class and Objects

ITI Introduction to Computing II

Object. OutputStream write(int) write(byte[]) write(byte[], int, int) FilterOutputStream write(int) write(byte[]) write(byte[], int, int)

Polymorphism and Interfaces

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Introduction to Java. March 1, 2001 CBRSS and the John M. Olin Institute for Strategic Studies Lars-Erik Cederman

QUESTIONS FOR AVERAGE BLOOMERS

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Transcription:

SECTION A (10 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (5 Marks) i. Which of the following is not a valid primitive type : a. char b. double c. int d. data ii. Which of the following is not a valid variable name : a. My_var b. Myvar1 c. My$var d. 1Myvar iii. iv.... is a method of Scanner claas. a. new() b. print() c. println() d. next() In the following class declaration,. is the superclass. a. Class2 b. Class1 c. Class1 and class2 d. None of the above v. In the following diagram,. method illustrates the concept of polymorphism. a. Shape b. Line c. Draw d. Circle 1 (b) Fill in the Blanks: (5 Marks) i. An object, on the other hand, is a unique instance of a filled-in template for which attribute values have been provided, and upon which methods may be performed. ii. iii. iv. Before a variable can be used in a Java program, the type and name of the variable must be declared to the Java compiler. The term instantiation.. is used to refer to the process by which an object is created in memory at run time based upon a class definition. Information Hiding... means that you separate the description of how to use a class from the implementation details, such as how the class methods are defined. v. Inheritance... is a compile-time mechanism in Java that allows you to extend a class (called the base class or superclass) with another class (called the derived class or subclass).

SECTION B (5 x 3 = 15 MARKS) Answer any FIVE Questions. Each Question carries THREE Marks. 2. Following is the code snippet of a Java program: Answer the following questions based on the above code: (i) Write down the names of attributes in the code shown. (ii) Write down the names of methods in the code shown. (iii) Write down the names of object in the code shown. Ans[ 2 ]: Attributes: Mehods: Object: myname,myid myinfo,main firstperson 3. Following is the code snippet of a Java Program: Answer the following questions based on the above code: (i) Write down the names of attributes that are inherited in the ItemInfo class. (ii) Write down the names of methods that are inherited in the ItemInfo class. Ans[ 3 ]: Attributes: Methods: ItemName dispiteminfo 4. Write a code to declare a class using public and private modifiers. Ans[ 4 ]: class test public double att1; private int att2;

5. Differentiate between if statement and switch statement. Ans[ 5 ]: if conditional statement provides the branching based on its condition. A switch statement is similar to an if-else construct in that it allows the conditional execution of one or more lines of code. 6. Write a code to declare and create an array of Objects. Ans[ 6 ]: Class student String stdname; int stdid; class Example public static void main(string args [ ]) Student[ ] students = new Student[10]; for ( i=0;i<10;i++) students[i] = new Student( ); 7. What is the difference between a class and an interface in Java? Ans[ 7 ]: A class defines: The data structure (i.e., the names and types of attributes) of each and every object belonging to that class The operations/methods to be performed by such objects: An interface specifies a set of methods that any class that implements the interface: Contains method headings and constant definitions only. Contains neither instance variables nor any complete method definitions.

SECTION C (3 x 5 = 15 MARKS) Answer any THREE Questions. Each Question carries FIVE Marks. 8. Write a program to implement the concept of method overriding(polymorphism). Ans[ 8 ]: Any program of polymorphism OR class Box public void info() System.out.println("This is a simple box"); class SteelBox extends Box public void info() System.out.println("This is a steel box"); class WoddenBox extends Box public void info() System.out.println("This is a Wodden box"); class LargeWoddenBox extends WoddenBox public void info() System.out.println("This is a Huge Wodden box"); class BoxDemo public static void main(string ary[]) Box b = new Box(); WoddenBox wb = new WoddenBox(); SteelBox sb = new SteelBox(); LargeWoddenBox lwb = new LargeWoddenBox(); b.info(); wb.info(); sb.info(); lwb.info();

9. Write a program that performs following tasks: i. Creates a class named Course havig attributes(coursename, CourseID, CourseLevel). ii. Writes a method named CourseInfo in Course class to display CourseName, CourseID, CourseLevel. iii. Creates two objects of the Course class in another class and assign the values to it as shown below: Course Name Course ID Course Level OOP 213 5 C++ 221 3 Ans[ 9 ]: class Course String coursename; int courseid; int courselevel; void CourseInfo() System.out.prinltln( CourseName is + coursename); System.out.prinltln( CourseID is + courseid); System.out.prinltln( CourseLevel is + courselevel); class Example public static void main (String args[ ]) //*************** Creating Two Courses ******** Course course_1 = new Course (); Course course_2 = new Course (); course_1.courseid=213; course_1.coursename="oop"; course_1.courselevel=5; course_2.courseid=221; course_2.coursename="c++"; course_2.courselevel=3; course1.courseinfo(); course2.courseinfo();

10. Consider the following class declarations: Find out the valid and Not invalid statements in the code shown above.

Ans[ 10 ]:

11. Find out the getter and setter methods in the following class declaration: class Employee private String firstname; private String lastname; private double monthlysalary; public String getfirstname() return firstname; public void setfirstname(string fname) firstname = fname; public String getlastname() return lastname; public void setlastname(string lname) lastname = lname; public double getmonthlysalary() return monthlysalary; public void setmonthlysalary(double m) if(m < 0) monthlysalary =0; else monthlysalary = m; Ans[ 11 ]: Getter Methods: Setter Mehods: getfirstname, getlastname, getmonthlysalary setfirstname, setlastname, setmonthlysalary