Question

1. Provide a definition for the term abstraction. Give an example in the context of programming 2. In object oriented program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Abstraction can be simply defined as hiding necessary information.

or

Abstraction is selecting data from a larger pool of data to show only the relevant details to the object. It helps to reduce programming complexity and effort.

Example : Classes in c++

classes in c++ can decide which data member will be visible and which will be not. example members declared as public can be accessed from anywhere whereas members declared as private can be accessed only within the class.

2. the main difference between composition and inheritance is :

composition allows us to reuse code without extending the class whereas inheritance needs to extend the class in order to reuse the code.

composition allows us to reuse code even for final class which is not extensible whereas inheritance doesn't allow in such cases.

Examples:

Inheritance :

class Fruit {

//... }

class Apple extends Fruit {

//... }

composition :

class Fruit {

//... }

class Apple {

private Fruit fruit = new Fruit(); //... }

3. declare two classes with Teams & Games. then declare n objects as n teams like Team 1,Team 2......etc, and store the attributes of each team i.e players of the team. similarly in game class declare all n games and store their respective attributes such as which two teams played the game and their scores.

you can take the below program for reference:

public class Dog

{

    // Instance Variables

    String name;

    String breed;

    int age;

    String color;

  

    // Constructor Declaration of Class

    public Dog(String name, String breed,

                   int age, String color)

    {

        this.name = name;

        this.breed = breed;

        this.age = age;

        this.color = color;

    }

  

    // method 1

    public String getName()

    {

        return name;

    }

  

    // method 2

    public String getBreed()

    {

        return breed;

    }

  

    // method 3

    public int getAge()

    {

        return age;

    }

  

    // method 4

    public String getColor()

    {

        return color;

    }

  

    @Override

    public String toString()

    {

        return("Hi my name is "+ this.getName()+

               ".\nMy breed,age and color are " +

               this.getBreed()+"," + this.getAge()+

               ","+ this.getColor());

    }

  

    public static void main(String[] args)

    {

        Dog tuffy = new Dog("tuffy","papillon", 5, "white");

        System.out.println(tuffy.toString());

    }

}

Add a comment
Know the answer?
Add Answer to:
1. Provide a definition for the term abstraction. Give an example in the context of programming...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what...

    SHORT ANSWER QUESTIONS Part 1 Classes Abstraction: What is Abstraction in terms of representation? Specifically what choices does one make when creating a class that is an example of Abstraction? Encapsulation: What is encapsulation? What is information hiding? What does a public interface to a class consist of (not in the sense of actual java interfaces but what the client uses to manipulate objects of the class) What is an object of a class? What is the constructor? How do...

  • Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in...

    Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in interesting ways. Now you’ll get a chance to use more of what objects offer, implementing inheritance and polymorphism and seeing them in action. You’ll also get a chance to create and use abstract classes (and, perhaps, methods). After this project, you will have gotten a good survey of object-oriented programming and its potential. This project won’t have a complete UI but will have a...

  • Item 1 Original Source Material Student Version Even though the first digital prototype was not fully...

    Item 1 Original Source Material Student Version Even though the first digital prototype was not fully functional, designers were able to emulate playing the game by selecting diffusion activities and staff members. Through this interaction, designers noticed that players would need to move the mouse from one side of the monitor to the other for every single turn in the game. Designers also realized that the natural order of the "Activity" and "Staff members" sections were inverted because players need...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • java Object Oriented Programming The assignment can be done individually or in teams of two. Submit one as...

    java Object Oriented Programming The assignment can be done individually or in teams of two. Submit one assignment per team of two via Omnivox and NOT MIO.Assignments sent via MIO will be deducted marks. Assignments must be done alone or in groups and collaboration between individuals or groups is strictly forbidden. There will be a in class demo on June 1 make sure you are prepared, a doodle will be created to pick your timeslot. If you submit late, there...

  • What an Executive Summary Is An executive summary is a specific type of document that does...

    What an Executive Summary Is An executive summary is a specific type of document that does two things: it summarizes a research article, and it offers recommendations as to how information from the article can be used. Some long reports can contain an executive summary section, as indicated in the Pearson handbook. Write a 2 pahe Executive Summary In business contexts, an executive summary is always written for a specific purpose: to explain the information in the article to a...

  • Summary Write a program that demonstrates the skills you’ve learned throughout this quarter. This type of...

    Summary Write a program that demonstrates the skills you’ve learned throughout this quarter. This type of project offers only a few guidelines and requirements, allowing you to invest as much time, effort and imagination as you want.  Submit your java programs (*.java) and any other I/O (*.txt) via Canvas  You’ve worked quite hard to make it this far, so have a bit of fun with this project! Design Brief: Use Case Scenario You are hired to develop a...

  • The case on Tata Steel captures the success story of Tata Steel very effectively as to...

    The case on Tata Steel captures the success story of Tata Steel very effectively as to how a giant corporation, led by a world-class management team, reinvents itself and sets out on a growth path when faced with dramatic challenges from the environment. This analysis is aimed at summarizing some of the issues and the challenges Tata Steel is likely to face in the years ahead. An attempt has also been made to arrive at some broad strategies and initiatives...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

  • Playgrounds and Performance: Results Management at KaBOOM! (A) We do this work because we want to...

    Playgrounds and Performance: Results Management at KaBOOM! (A) We do this work because we want to make a difference in the world; how can we go further faster? - Darell Hammond, CEO and co-founder, KaBOOM! Darell Hammond stepped onto the elementary school playground and took a long, slow look around. It was 8 a.m. on an unusually warm fall day in 2002 and the playground was deserted, but Hammond knew the children would start arriving soon to admire their new...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT