Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q.1 Write a Java Program to do the following. (Marks:3) a) Create a class Teacher with the field collegeName type String, designation Type String and

image text in transcribed

image text in transcribed

Q.1 Write a Java Program to do the following. (Marks:3) a) Create a class Teacher with the field collegeName type String, designation Type String and a method work(). b) Create a sub class PhysicsTeacher of Teacher. Which have single field mainSubject of type String and main method. C) Create an object "obj" of PhysicsTeacher inside class PhysicsTeacher. Show, how we can call field collegeName, designation and method work() using object "obj". Q.2 Assume that you see the following lines of code: (Marks:2) Device dev = new Printer(); dev.getName(); a) Printer is a subclass of Device, which of these classes must have a definition of method getName for this code to compile? b) if both classes have an implementation of getName, which one will be executed? Q.3 Consider the following interface Vehicle. (Marks:3) interface Vehicle \{ void changeGear(char newGear); void increaseSpeed(int newSpeed); void decreaseSpeed(int newSpeed); \} a) Create the classes Car and Bus that implements the methods of interface Vehicle. b) Add gear and speed fields in Car and Bus classes. c) changeGear() method sets the gear field by newGear value. d) increasespeed() method increases the speed field by newSpeed value. e) decreaseSpeed () method decreases the speed field by newSpeed value. Q.4 Can an abstract class have concrete (non-abstract) methods? Can a concrete class have abstract methods? Can you have an abstract class without abstract methods? Justify your answers. (Marks:2) Q1) Create a class Travel_Package having fields Destination, TourGuideName, PackageCode,and Price. Declare a mutator method namely updatePrice() to increase the Price by 300 SAR.Suppose the Price before update was 3800 SAR. (2.5 Marks) Q2) Create a class World with fields continents and countries and implement the concept of constructor overloading. Declare 3 constructors (Empty constructor, constructor with one parameter, Constructor with two parameter). (2.5 Marks) Q3) Create a class Shape that defines a variable named window of type Rectangle, and then create a rectangle object and assign it to the variable window. The rectangle constructor has two int parameters. (2.5 Marks) COMP214/Lab Assignment/ 2022-2023/Second Semester Q4) Consider the following class diagram and answer the following: (2.5 Marks) Which one of the following assignments are legal, and why or why not? i) Person p1 = new Student(); ii) PhDStudent phd = new Student(); iii) Teacher t1= new Person()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions