Code Monkey home page Code Monkey logo

java_week2_assessment's Introduction

Java Week2_Assessment:

Questions:

  1. Using inheritance, one class can acquire the properties of others. Consider the following Animal class: class Animal{ void walk(){ System.out.println("I am walking"); } }

This class has only one method, walk. Next, we want to create a Bird class that also has a fly method. We do this using extends keyword: class Bird extends Animal { void fly() { System.out.println("I am flying"); } }

Finally, we can create a Bird object that can both fly and walk.

public class Solution{ public static void main(String[] args){

  Bird bird = new Bird();
  bird.walk();
  bird.fly();

} }

The above code will print: I am walking I am flying

This means that a Bird object has all the properties that an Animal object has, as well as some additional unique properties. You must add a sing method to the Bird class, then modify the main method accordingly so that the code prints the following lines:

I am walking I am flying I am singing

  1. Create a class named 'Member' having the following members:

Data members

1 - Name 2 - Age 3 - Phone number 4 - Address 5 - Salary

It also has a method named 'printSalary' which prints the salary of the members. Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these classes and print the same.

  1. Write a program that would print the information (name, year of joining, salary, address) of three employees by creating a class named 'Employee'. The output should be as follows:

Name Year of joining Address Robert 1994 64C- WallsStreat Sam 2000 68D- WallsStreat John 1999 26B- WallsStreat

  1. Define a method to calculate power of a number raised to other i.e. ab using recursion where the numbers 'a' and 'b' are to be entered by the user.

java_week2_assessment's People

Contributors

abdulwasih2003 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.