SlideShare a Scribd company logo
1 of 3
(Inheritance and Polymorphism) In java, No UML is needed.
I 1.10 Implement MyStack using inheritance) In Listing 11.10 MyStack is imple mented using
composition. Define a new stack class that extends ArrayList. Draw the UML diagram for the
classes and then implement MyStack. Write a test program that prompts the user to enter five
strings and displays them in reverse order
Solution
StackTest.java
import java.util.ArrayList;
import java.util.Scanner;
public class StackTest extends ArrayList{
/**
* @param args
*/
public boolean isEmpty(){
return super.isEmpty();
}
public int getSize(){
return super.size();
}
public Object peek(){
return super.get(getSize() - 1);
}
public Object pop(){
Object o = super.get(getSize()-1);
super.remove(getSize()-1);
return o;
}
public void pust(Object o){
super.add(o);
}
public String toString(){
return "Stack: "+super.toString();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new StackTest();
}
public StackTest(){
Scanner scan = new Scanner(System.in);
for(int i=1; i<=5; i++){
System.out.println("Enter String "+i+": ");
pust(scan.nextLine());
}
System.out.println("Given String in stack "+toString());
System.out.println("Reverse Order :");
for(int i=1; i<=5; i++){
System.out.println(pop());
}
}
}
Output:
Enter String 1:
AAA
Enter String 2:
BBB
Enter String 3:
CCC
Enter String 4:
DDD
Enter String 5:
EEE
Given String in stack Stack: [AAA, BBB, CCC, DDD, EEE]
Reverse Order :
EEE
DDD
CCC
BBB
AAA
(Inheritance and Polymorphism) In java- No UML is needed- I 1-10 Imple.docx

More Related Content

Similar to (Inheritance and Polymorphism) In java- No UML is needed- I 1-10 Imple.docx

Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
SpreadsheetWriter.javaCan you please help me the JAVA program Let.pdf
SpreadsheetWriter.javaCan you please help me the JAVA program Let.pdfSpreadsheetWriter.javaCan you please help me the JAVA program Let.pdf
SpreadsheetWriter.javaCan you please help me the JAVA program Let.pdfezonesolutions
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
Java PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptxJava PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptxssuser99ca78
 
stack in java ds - muhammed sdasdasdasdasdas.ppt
stack in java ds - muhammed sdasdasdasdasdas.pptstack in java ds - muhammed sdasdasdasdasdas.ppt
stack in java ds - muhammed sdasdasdasdasdas.pptssusere3b1a2
 
11slide
11slide11slide
11slideIIUM
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfsiennatimbok52331
 
Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Matt
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdfanithareadymade
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet KotlinJieyi Wu
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manualChandrapriya Jayabal
 
A linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdfA linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdfkisgstin23
 

Similar to (Inheritance and Polymorphism) In java- No UML is needed- I 1-10 Imple.docx (20)

Java Programs
Java ProgramsJava Programs
Java Programs
 
SpreadsheetWriter.javaCan you please help me the JAVA program Let.pdf
SpreadsheetWriter.javaCan you please help me the JAVA program Let.pdfSpreadsheetWriter.javaCan you please help me the JAVA program Let.pdf
SpreadsheetWriter.javaCan you please help me the JAVA program Let.pdf
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Java PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptxJava PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptx
 
Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 
JUnit PowerUp
JUnit PowerUpJUnit PowerUp
JUnit PowerUp
 
stack in java ds - muhammed sdasdasdasdasdas.ppt
stack in java ds - muhammed sdasdasdasdasdas.pptstack in java ds - muhammed sdasdasdasdasdas.ppt
stack in java ds - muhammed sdasdasdasdasdas.ppt
 
11slide
11slide11slide
11slide
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
 
3 j unit
3 j unit3 j unit
3 j unit
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
11slide.ppt
11slide.ppt11slide.ppt
11slide.ppt
 
Static keyword.pptx
Static keyword.pptxStatic keyword.pptx
Static keyword.pptx
 
We will be making 4 classes Main - for testing the code Hi.pdf
 We will be making 4 classes Main - for testing the code Hi.pdf We will be making 4 classes Main - for testing the code Hi.pdf
We will be making 4 classes Main - for testing the code Hi.pdf
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet Kotlin
 
(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual
 
A linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdfA linked stack is implemented using a standard Node class as follows.pdf
A linked stack is implemented using a standard Node class as follows.pdf
 

More from dorisc7

(TCO 2) Which of the following project management activities is associ.docx
(TCO 2) Which of the following project management activities is associ.docx(TCO 2) Which of the following project management activities is associ.docx
(TCO 2) Which of the following project management activities is associ.docxdorisc7
 
(TCO 1) Who are the users of managerial accounting information- How do.docx
(TCO 1) Who are the users of managerial accounting information- How do.docx(TCO 1) Who are the users of managerial accounting information- How do.docx
(TCO 1) Who are the users of managerial accounting information- How do.docxdorisc7
 
(Subsequent events) Green- CPA- is auditing the financial statements o.docx
(Subsequent events) Green- CPA- is auditing the financial statements o.docx(Subsequent events) Green- CPA- is auditing the financial statements o.docx
(Subsequent events) Green- CPA- is auditing the financial statements o.docxdorisc7
 
(Reliability engineering) Make a list of six population stereotypical.docx
(Reliability engineering) Make a list of six population stereotypical.docx(Reliability engineering) Make a list of six population stereotypical.docx
(Reliability engineering) Make a list of six population stereotypical.docxdorisc7
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docxdorisc7
 
-Java programming- Write a class named Junior-java Inherits the Stud.docx
-Java programming-  Write a class named Junior-java  Inherits the Stud.docx-Java programming-  Write a class named Junior-java  Inherits the Stud.docx
-Java programming- Write a class named Junior-java Inherits the Stud.docxdorisc7
 
--Social Organizations and Core Competencies-- Please respond to the f.docx
--Social Organizations and Core Competencies-- Please respond to the f.docx--Social Organizations and Core Competencies-- Please respond to the f.docx
--Social Organizations and Core Competencies-- Please respond to the f.docxdorisc7
 
-- I have two classes One is Carnivore and the other is Herbivore- Eac.docx
-- I have two classes One is Carnivore and the other is Herbivore- Eac.docx-- I have two classes One is Carnivore and the other is Herbivore- Eac.docx
-- I have two classes One is Carnivore and the other is Herbivore- Eac.docxdorisc7
 
- Answer the following questions about acids 1- What is the phase of a.docx
- Answer the following questions about acids 1- What is the phase of a.docx- Answer the following questions about acids 1- What is the phase of a.docx
- Answer the following questions about acids 1- What is the phase of a.docxdorisc7
 
- At time 110 four processes (P1 P4) are waiting for a timeout signal.docx
- At time 110 four processes (P1  P4) are waiting for a timeout signal.docx- At time 110 four processes (P1  P4) are waiting for a timeout signal.docx
- At time 110 four processes (P1 P4) are waiting for a timeout signal.docxdorisc7
 
(70 pts) Nuclear History Identify the event in nuclear history that oc.docx
(70 pts) Nuclear History Identify the event in nuclear history that oc.docx(70 pts) Nuclear History Identify the event in nuclear history that oc.docx
(70 pts) Nuclear History Identify the event in nuclear history that oc.docxdorisc7
 
(2) The CPU incorporates several major components (as shown in Fig- de.docx
(2) The CPU incorporates several major components (as shown in Fig- de.docx(2) The CPU incorporates several major components (as shown in Fig- de.docx
(2) The CPU incorporates several major components (as shown in Fig- de.docxdorisc7
 
(Audit evidence) The third GAAS of field work requires that the audito.docx
(Audit evidence) The third GAAS of field work requires that the audito.docx(Audit evidence) The third GAAS of field work requires that the audito.docx
(Audit evidence) The third GAAS of field work requires that the audito.docxdorisc7
 
What is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docx
What is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docxWhat is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docx
What is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docxdorisc7
 
What is the concept of sustainable income- Please describe it in your.docx
What is the concept of sustainable income- Please describe it in your.docxWhat is the concept of sustainable income- Please describe it in your.docx
What is the concept of sustainable income- Please describe it in your.docxdorisc7
 
What is the backbone for the Internet- Briefly describe how the Intern.docx
What is the backbone for the Internet- Briefly describe how the Intern.docxWhat is the backbone for the Internet- Briefly describe how the Intern.docx
What is the backbone for the Internet- Briefly describe how the Intern.docxdorisc7
 
What is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docx
What is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docxWhat is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docx
What is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docxdorisc7
 
what is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docx
what is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docxwhat is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docx
what is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docxdorisc7
 
What is the pH of a 0-114 M solution of the acid HA if its ionization (1).docx
What is the pH of a 0-114 M solution of the acid HA if its ionization (1).docxWhat is the pH of a 0-114 M solution of the acid HA if its ionization (1).docx
What is the pH of a 0-114 M solution of the acid HA if its ionization (1).docxdorisc7
 
What is the minimum number of nodes in an AVL tree of height 8- Let N(.docx
What is the minimum number of nodes in an AVL tree of height 8- Let N(.docxWhat is the minimum number of nodes in an AVL tree of height 8- Let N(.docx
What is the minimum number of nodes in an AVL tree of height 8- Let N(.docxdorisc7
 

More from dorisc7 (20)

(TCO 2) Which of the following project management activities is associ.docx
(TCO 2) Which of the following project management activities is associ.docx(TCO 2) Which of the following project management activities is associ.docx
(TCO 2) Which of the following project management activities is associ.docx
 
(TCO 1) Who are the users of managerial accounting information- How do.docx
(TCO 1) Who are the users of managerial accounting information- How do.docx(TCO 1) Who are the users of managerial accounting information- How do.docx
(TCO 1) Who are the users of managerial accounting information- How do.docx
 
(Subsequent events) Green- CPA- is auditing the financial statements o.docx
(Subsequent events) Green- CPA- is auditing the financial statements o.docx(Subsequent events) Green- CPA- is auditing the financial statements o.docx
(Subsequent events) Green- CPA- is auditing the financial statements o.docx
 
(Reliability engineering) Make a list of six population stereotypical.docx
(Reliability engineering) Make a list of six population stereotypical.docx(Reliability engineering) Make a list of six population stereotypical.docx
(Reliability engineering) Make a list of six population stereotypical.docx
 
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
 
-Java programming- Write a class named Junior-java Inherits the Stud.docx
-Java programming-  Write a class named Junior-java  Inherits the Stud.docx-Java programming-  Write a class named Junior-java  Inherits the Stud.docx
-Java programming- Write a class named Junior-java Inherits the Stud.docx
 
--Social Organizations and Core Competencies-- Please respond to the f.docx
--Social Organizations and Core Competencies-- Please respond to the f.docx--Social Organizations and Core Competencies-- Please respond to the f.docx
--Social Organizations and Core Competencies-- Please respond to the f.docx
 
-- I have two classes One is Carnivore and the other is Herbivore- Eac.docx
-- I have two classes One is Carnivore and the other is Herbivore- Eac.docx-- I have two classes One is Carnivore and the other is Herbivore- Eac.docx
-- I have two classes One is Carnivore and the other is Herbivore- Eac.docx
 
- Answer the following questions about acids 1- What is the phase of a.docx
- Answer the following questions about acids 1- What is the phase of a.docx- Answer the following questions about acids 1- What is the phase of a.docx
- Answer the following questions about acids 1- What is the phase of a.docx
 
- At time 110 four processes (P1 P4) are waiting for a timeout signal.docx
- At time 110 four processes (P1  P4) are waiting for a timeout signal.docx- At time 110 four processes (P1  P4) are waiting for a timeout signal.docx
- At time 110 four processes (P1 P4) are waiting for a timeout signal.docx
 
(70 pts) Nuclear History Identify the event in nuclear history that oc.docx
(70 pts) Nuclear History Identify the event in nuclear history that oc.docx(70 pts) Nuclear History Identify the event in nuclear history that oc.docx
(70 pts) Nuclear History Identify the event in nuclear history that oc.docx
 
(2) The CPU incorporates several major components (as shown in Fig- de.docx
(2) The CPU incorporates several major components (as shown in Fig- de.docx(2) The CPU incorporates several major components (as shown in Fig- de.docx
(2) The CPU incorporates several major components (as shown in Fig- de.docx
 
(Audit evidence) The third GAAS of field work requires that the audito.docx
(Audit evidence) The third GAAS of field work requires that the audito.docx(Audit evidence) The third GAAS of field work requires that the audito.docx
(Audit evidence) The third GAAS of field work requires that the audito.docx
 
What is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docx
What is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docxWhat is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docx
What is the Big Bang-SolutionBig Bang is a theory which talks ababo th.docx
 
What is the concept of sustainable income- Please describe it in your.docx
What is the concept of sustainable income- Please describe it in your.docxWhat is the concept of sustainable income- Please describe it in your.docx
What is the concept of sustainable income- Please describe it in your.docx
 
What is the backbone for the Internet- Briefly describe how the Intern.docx
What is the backbone for the Internet- Briefly describe how the Intern.docxWhat is the backbone for the Internet- Briefly describe how the Intern.docx
What is the backbone for the Internet- Briefly describe how the Intern.docx
 
What is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docx
What is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docxWhat is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docx
What is the pH of a 0-1 M aqueous solution of NaH2PO4SolutionNaH2PO4 -.docx
 
what is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docx
what is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docxwhat is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docx
what is the ph of a 0-16M NaF(aq) solution-SolutionNaF(aq) -----------.docx
 
What is the pH of a 0-114 M solution of the acid HA if its ionization (1).docx
What is the pH of a 0-114 M solution of the acid HA if its ionization (1).docxWhat is the pH of a 0-114 M solution of the acid HA if its ionization (1).docx
What is the pH of a 0-114 M solution of the acid HA if its ionization (1).docx
 
What is the minimum number of nodes in an AVL tree of height 8- Let N(.docx
What is the minimum number of nodes in an AVL tree of height 8- Let N(.docxWhat is the minimum number of nodes in an AVL tree of height 8- Let N(.docx
What is the minimum number of nodes in an AVL tree of height 8- Let N(.docx
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

(Inheritance and Polymorphism) In java- No UML is needed- I 1-10 Imple.docx

  • 1. (Inheritance and Polymorphism) In java, No UML is needed. I 1.10 Implement MyStack using inheritance) In Listing 11.10 MyStack is imple mented using composition. Define a new stack class that extends ArrayList. Draw the UML diagram for the classes and then implement MyStack. Write a test program that prompts the user to enter five strings and displays them in reverse order Solution StackTest.java import java.util.ArrayList; import java.util.Scanner; public class StackTest extends ArrayList{ /** * @param args */ public boolean isEmpty(){ return super.isEmpty(); } public int getSize(){ return super.size(); } public Object peek(){ return super.get(getSize() - 1); } public Object pop(){ Object o = super.get(getSize()-1); super.remove(getSize()-1); return o; } public void pust(Object o){ super.add(o);
  • 2. } public String toString(){ return "Stack: "+super.toString(); } public static void main(String[] args) { // TODO Auto-generated method stub new StackTest(); } public StackTest(){ Scanner scan = new Scanner(System.in); for(int i=1; i<=5; i++){ System.out.println("Enter String "+i+": "); pust(scan.nextLine()); } System.out.println("Given String in stack "+toString()); System.out.println("Reverse Order :"); for(int i=1; i<=5; i++){ System.out.println(pop()); } } } Output: Enter String 1: AAA Enter String 2: BBB Enter String 3: CCC Enter String 4: DDD Enter String 5: EEE Given String in stack Stack: [AAA, BBB, CCC, DDD, EEE] Reverse Order : EEE DDD CCC BBB AAA