Question

I need a simple java program that contains all the following subjects : 1- OOP Objects...

I need a simple java program that contains all the following subjects :

1- OOP Objects -Classes

2- Encapsulation

3- Polymorphism

4-Inheritance

4- Abstract Classes

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

Please comment if you have any doubt

Code:

class Main1
{
   public int a=4,b=5;
   //Class Main1 is the Parent class
   void show1()
   {
       System.out.println("Main Class,a="+a+",b="+b);
   }
}
class One extends Main1
{
   //Class One is the child class of Main1
   void show()
   {
       System.out.println("Single Inheritence,a="+a+",b="+b);
   }
}
class Poly1{
   //Polymorphism means of more then one form
   //here a has two forms in Poly1 and Poly2
   int a=5;
}
class Poly2 extends Poly1{
   int a=10;
}
class Encapsule{
   private int a=5;
   //private is the key word used to encapsulate(hide) the data
   public int getA(){
       //getter methods are used to get data
       return a;
   }
}
class NewClass{
   //This is a OOP class
   void show(){
       System.out.println("This is a NewClass Object");
   }
}
abstract class Abs{
   //this is a abstract class for Abstraction
   //absract method must be defined in the child class
   abstract int add(int a,int b);
}
class Abs1 extends Abs{
   //method definition for abstract int add(int a,int b);
   int add(int a,int b){
       return a+b;
   }
}
public class MyClass{
   public static void main(String[] args) {
       //this is a OOP Object
       System.out.println("1- OOP Objects -Classes");
       NewClass obj=new NewClass();
       obj.show();

       //Encapsulation
       System.out.println("\n2- Encapsulation");
       Encapsule ens=new Encapsule();
       System.out.println(ens.getA());

       //Polymorphism
       System.out.println("\n3- Polymorphism");
       Poly1 poly=new Poly2();
       System.out.println(poly.a);

       //Inheritance
       System.out.println("\n4-Inheritance");
       One e=new One();
       e.show();

       //Abstract Classes
       System.out.println("\n5- Abstract Classes");
       Abs abs=new Abs1();
       System.out.println(abs.add(2,3));
   }
}

Screenshot:

class Main1 public int a=4,b=5; //Class Mainl is the Parent class void show1() System.out.println(Main Class, a=+a+, b=+b

public class MyClass{ public static void main(String[] args) { //this is a OOP Object System.out.println(1- OOP Objects -Cla

Output:

1- OOP Objects -Classes This is a Newclass Object 2- Encapsulation 3- Polymorphism 4-Inheritance Single Inheritence, a=4, b=5

Add a comment
Know the answer?
Add Answer to:
I need a simple java program that contains all the following subjects : 1- OOP Objects...
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
  • JAVA - Abstraction and Encapsulation are one pillar of OOP (Object Oriented Programming). Another is inheritance...

    JAVA - Abstraction and Encapsulation are one pillar of OOP (Object Oriented Programming). Another is inheritance and polymorphism. In this assignment we will use inheritance and polymorphism to solve a problem. Part (a) of the figure below shows a symbolic representation of an electric circuit called an amplifier. The input to the amplifier is the voltage vi and the output is the voltage vo. The output of an amplifier is proportional to the input. The constant of proportionality is called...

  • I have this java program that I need to add an abstract method and polymorphism to...

    I have this java program that I need to add an abstract method and polymorphism to it : import java.util.Scanner; //class and encapsulation class BookTheTicket { private String movieName; private String theatreName; private int ticketCost; void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 "); } } // inheritence class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi...

  • program Java oop The project description As a programmer; you have been asked to write a...

    program Java oop The project description As a programmer; you have been asked to write a program for a Hospital with the following The Hospital has several employees and each one of them has an ID, name, address, mobile number, email and salary. . The employees are divided into Administration staff: who have in addition to the previous information their position. Nurse: who have their rank and specialty stored in addition to the previous o o Doctor: who have the...

  • You are given a specification for some Java classes as follows.   A building has a number...

    You are given a specification for some Java classes as follows.   A building has a number of floors, and a number of windows. A house is a building. A garage is a building. (This isn’t Florida-like … it’s a detached garage.) A room has a length, width, a floor covering, and a number of closets. You can never create an instance of a building, but every object that is a building must have a method that calculates the floor space,...

  • Write a C+OOP program that simulates a vending machine. The program should define at least two...

    Write a C+OOP program that simulates a vending machine. The program should define at least two classes. Less than two classes will result in 20 points deduction. (30 points) One must be general vending machine (50 points) The other can be either vending machine of soda, or vending machine of snack. It must be a subclass of above general machine These vending machines should have following components and functions e Coin slot o Allow adding coins o Display total coin...

  • write in java code. oop. i dont have its written code. i have its output in...

    write in java code. oop. i dont have its written code. i have its output in the thrid picture and how the inheritance works with the second picture. just need it in full written code and uni class will be. jus need you to write the whole code for me as its an extra question which i need for my preparation of my exam. add as you but it must be correct and similar to the question Inheritance Do the...

  • Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student...

    Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student will demonstrate the ability to use inheritance in Java programs. Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following: Person Automobile Animal Based on your choice: If you choose Person, you will create a subclass of Person called Student. If you choose Automobile, you will create...

  • Hi I need help creating a program in JAVA. This is material from chapter 9 Objects...

    Hi I need help creating a program in JAVA. This is material from chapter 9 Objects and Classes from the Intro to JAVA textbook. Mrs. Quackenbush's Rent-A-Wreck car rental ..... Mrs. Q asked you to create a program that can help her track her growing fleet of junkers. Of course she expects you to use your best programming skills, including: 1. Plan and design what attributes/actions an automobile in a rental fleet should have (example. Track number of Trucks, SUVs,...

  • write a source code anything related to cars. code need to be interesting and code needs...

    write a source code anything related to cars. code need to be interesting and code needs to include all topic listed below Object classes and advanced object classes Inheritance (simple and/or abstract and/or interfaces), polymorphism, aggregation/data leaks File I/O and exceptions String processing Graphical User Interfaces (GUIS) Simple data structures

  • Write ONE application program by using the following requirements: Using JAVA File input and outp...

    Write ONE application program by using the following requirements: Using JAVA File input and output Exception handling Inheritance At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods At least one interface: this interface needs to have at least two abstract methods At least one method overloading At least one method overriding At least...

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