Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want all the answers in code. Q.1 Write a Java Program to do the following. (Marks:3) a) Create a class Teacher with the field

image text in transcribed

I want all the answers in code.

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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions