SlideShare a Scribd company logo
2016 Winter
LAB #4
Prepared by: Berk Soysal
Inheritance is one of the most important
features of Object-Oriented Programming
(OOP).
Inheritance allows a class to get the properties
and methods of another class. In other words,
the derived class inherits the states and
behaviors from the base class. The derived class
is also called subclass and the base class is also
known as super-class.
2016 Winter
Every Class extends the Object Class
The Object class, in the java.lang package, sits at the top of the class hierarchy tree.
Every class is a descendant, direct or indirect, of the Object class.
Every class you use or write inherits the instance methods of Object class.
You need not use any of these methods, but, if you choose to do so,
you may need to override them with code that is specific to your class.
Some methods inherited from Object class are shown below:
•protected Object clone() throws CloneNotSupportedException
Creates and returns a copy of this object.
•public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
•protected void finalize() throws Throwable
Called by the garbage collector on an object when garbage
collection determines that there are no more references to the object
•public String toString()
Returns a string representation of the object.
2016 Winter
To reduce the complexity and simplify the language,
multiple inheritance is NOT supported in Java.
2016 Winter
Vehicle.java
Car.java
Truck.java
2016 Winter Folder  Lab4 Lab4 Examples Inheritance
• Any class containing an abstract method is
an abstract class
• You must declare the class with the
keyword abstract:
abstract class MyClass {...}
• An abstract class is incomplete
– It has “missing” method bodies
• You cannot instantiate (create a new
instance of) an abstract class.
2016 Winter
2016 Winter
An interface is a way to describe what classes should
do, without specifying how they should do it. It’s not a class
but a set of requirements for classes that want to conform
to the interface, for example;
public interface Comparable {
int compareTo(Object otherObject);
}
This requires that any class implementing the Comparable
interface contains a compareTo method, and this method must
take an Object parameter and return an integer.
Folder  Lab4 Lab4 Examples Interface
• Why bother introducing two concepts: abstract class and interface?
abstract class Comparable {
public abstract int compareTo (Object otherObject);
}
public class Employee extends Comparable {
pulibc int compareTo(Object otherObject) { . . . }
}
public interface Comparable {
int compareTo (Object otherObject)
}
public class Employee implements Comparable {
public int compareTo (Object otherObject) { . . . }
}
• A class can only extend a single abstract class, but it can implement as
many interfaces as it wants
• An abstract class can have a partial implementation, protected parts, static
methods and so on, while interfaces are limited to public constants and
public methods with no implementation.
2016 Winter
2016 Winter
 An option pane is a simple dialog box for graphical
input/output
• Advantages:
– simple
– flexible (in some ways)
– looks better than printing out to the console
• Disadvantages:
– created with static methods;
not very object-oriented
– not very powerful (just simple dialog boxes)
2016 Winter
• public static void showMessageDialog(
Component parent, Object message)
Displays a message on a dialog
with an OK button.
• public static int showConfirmDialog(
Component parent, Object message)
Displays a message and list of
choices Yes, No, Cancel
• public static String showInputDialog(
Component parent, Object message)
Displays a message and text
field for input, and returns the
value entered as a String.
2016 Winter
• showMessageDialog is analogous to
System.out.println for displaying a simple message
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null,
"How's the weather?");
JOptionPane.showMessageDialog(null,
"Second message");
}
}
2016 Winter Folder  Lab4 Lab4 Examples JOptionPane
• showConfirmDialog analogous to a System.out.print
that prints a question, then reading an input value from the
user (can only be one of the provided choices)
import javax.swing.*;
public class Main {
public static void main(String[] args) {
int choice = JOptionPane.showConfirmDialog(null,
"Erase your hard disk?");
if (choice == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Disk erased!");
} else {
JOptionPane.showMessageDialog(null, "Cancelled.");
}
}
}
2016 Winter Folder  Lab4 Lab4 Examples JOptionPane
• showInputDialog is analogous to a
System.out.print that prints a question, then
reading an input value from the user (can be any value)
import javax.swing.*;
public class Main {
public static void main(String[] args) {
String name = JOptionPane.showInputDialog(null,
"What's yer name, pardner?");
JOptionPane.showMessageDialog(null, "Yeehaw, " + name);
}
}
2016 Winter Folder Lab4 Lab4 Examples JOptionPane
Swing is a GUI widget toolkit for Java. It is part of
Oracle's Java Foundation Classes (JFC) – an API for
providing a graphical user interface (GUI) for Java
programs.
Swing was developed to provide a more
sophisticated set of GUI components than the earlier
Abstract Window Toolkit (AWT).
2016 Winter
JFrame: a heavy-weight container used as the top-level window.
JPanel: a light-weight container used to organize GUI components.
2016 Winter
2016 Winter
2016 Winter
• The game Puzzler consists of a 7 × 7 board.
Initially, all the cells are filled with marbles from
one to five available colors.
• When the user clicks on a cell for the first time,
the cell and all the adjacent cells of the same
color are selected. The marbles are gray to
indicate this state of the game.
• When the user clicks a second time on a
selected cell, all the selected cells vanish.
Marbles fall from top to bottom, and left to
right, in order to fill the empty spaces.
• To win the game, the user must make all the
marbles vanish.
Click on a Yellow marble
Click again !
Folder  Lab4 Lab4 Examples Puzzle
You can clearly see the important role of inheritance and interface for
this game. Each of the three classes is derived from an existing class.
2016 Winter
2016 Winter
Ad

More Related Content

What's hot (20)

Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2
Nafis Ahmed
 
Knolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in ScalaKnolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in Scala
Ayush Mishra
 
Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in Scala
Ayush Mishra
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in Scala
Ayush Mishra
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
Martin Odersky
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
agorolabs
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
Michael Heron
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
Archana Gopinath
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
Sireesh K
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Rahul Jain
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
Pinky Anaya
 
Quick Scala
Quick ScalaQuick Scala
Quick Scala
Puneet Kumar
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
#_ varible function
#_ varible function #_ varible function
#_ varible function
abdullah al mahamud rosi
 
Variable
VariableVariable
Variable
abdullah al mahamud rosi
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator Overloading
Michael Heron
 
Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2Adobe Flash Actionscript language basics chapter-2
Adobe Flash Actionscript language basics chapter-2
Nafis Ahmed
 
Knolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in ScalaKnolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in Scala
Ayush Mishra
 
Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in Scala
Ayush Mishra
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in Scala
Ayush Mishra
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
Martin Odersky
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
agorolabs
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
Michael Heron
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
langer4711
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
Sireesh K
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Rahul Jain
 
Differences between method overloading and method overriding
Differences between method overloading and method overridingDifferences between method overloading and method overriding
Differences between method overloading and method overriding
Pinky Anaya
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator Overloading
Michael Heron
 

Similar to Java Tutorial Lab 4 (20)

ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
mohamedsamyali
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
DevaKumari Vijay
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
Java mcq
Java mcqJava mcq
Java mcq
avinash9821
 
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
ssuser7fe189
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
Java Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHatJava Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHat
Scholarhat
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
Sean McElrath
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
Inocentshuja Ahmad
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
MH Abid
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
MikeAdva
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
talha ijaz
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Design patterns
Design patternsDesign patterns
Design patterns
Anas Alpure
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
DevaKumari Vijay
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
Dima Statz
 
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Intro To C++ - Class 05 - Introduction To  Classes, Objects, & StringsIntro To C++ - Class 05 - Introduction To  Classes, Objects, & Strings
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Blue Elephant Consulting
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUEITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
mohamedsamyali
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
10-Lecture10_Leeeeeeeeeeeeeeeecture.pptx
ssuser7fe189
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
Java Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHatJava Interview Questions PDF By ScholarHat
Java Interview Questions PDF By ScholarHat
Scholarhat
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
Sean McElrath
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
Inocentshuja Ahmad
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
MH Abid
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
MikeAdva
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
DevaKumari Vijay
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
Dima Statz
 
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Intro To C++ - Class 05 - Introduction To  Classes, Objects, & StringsIntro To C++ - Class 05 - Introduction To  Classes, Objects, & Strings
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Blue Elephant Consulting
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Ad

More from Berk Soysal (6)

Guest author manual
Guest author manualGuest author manual
Guest author manual
Berk Soysal
 
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
Comparison of BER performances of  64-PSK and 64-QAM in  AWGN channelsComparison of BER performances of  64-PSK and 64-QAM in  AWGN channels
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
Berk Soysal
 
Biomedical project report detecting emg noise
Biomedical project report detecting emg noiseBiomedical project report detecting emg noise
Biomedical project report detecting emg noise
Berk Soysal
 
Self Evaluation Test
Self Evaluation Test Self Evaluation Test
Self Evaluation Test
Berk Soysal
 
Java Tutorial Lab 9
Java Tutorial Lab 9Java Tutorial Lab 9
Java Tutorial Lab 9
Berk Soysal
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8
Berk Soysal
 
Guest author manual
Guest author manualGuest author manual
Guest author manual
Berk Soysal
 
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
Comparison of BER performances of  64-PSK and 64-QAM in  AWGN channelsComparison of BER performances of  64-PSK and 64-QAM in  AWGN channels
Comparison of BER performances of 64-PSK and 64-QAM in AWGN channels
Berk Soysal
 
Biomedical project report detecting emg noise
Biomedical project report detecting emg noiseBiomedical project report detecting emg noise
Biomedical project report detecting emg noise
Berk Soysal
 
Self Evaluation Test
Self Evaluation Test Self Evaluation Test
Self Evaluation Test
Berk Soysal
 
Java Tutorial Lab 9
Java Tutorial Lab 9Java Tutorial Lab 9
Java Tutorial Lab 9
Berk Soysal
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8
Berk Soysal
 
Ad

Recently uploaded (20)

Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
Tools of the Trade: Linux and SQL - Google Certificate
Tools of the Trade: Linux and SQL - Google CertificateTools of the Trade: Linux and SQL - Google Certificate
Tools of the Trade: Linux and SQL - Google Certificate
VICTOR MAESTRE RAMIREZ
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Full Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest VersionFull Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest Version
jonesmichealj2
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
Tools of the Trade: Linux and SQL - Google Certificate
Tools of the Trade: Linux and SQL - Google CertificateTools of the Trade: Linux and SQL - Google Certificate
Tools of the Trade: Linux and SQL - Google Certificate
VICTOR MAESTRE RAMIREZ
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Full Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest VersionFull Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest Version
jonesmichealj2
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 

Java Tutorial Lab 4

  • 1. 2016 Winter LAB #4 Prepared by: Berk Soysal
  • 2. Inheritance is one of the most important features of Object-Oriented Programming (OOP). Inheritance allows a class to get the properties and methods of another class. In other words, the derived class inherits the states and behaviors from the base class. The derived class is also called subclass and the base class is also known as super-class. 2016 Winter
  • 3. Every Class extends the Object Class The Object class, in the java.lang package, sits at the top of the class hierarchy tree. Every class is a descendant, direct or indirect, of the Object class. Every class you use or write inherits the instance methods of Object class. You need not use any of these methods, but, if you choose to do so, you may need to override them with code that is specific to your class. Some methods inherited from Object class are shown below: •protected Object clone() throws CloneNotSupportedException Creates and returns a copy of this object. •public boolean equals(Object obj) Indicates whether some other object is "equal to" this one. •protected void finalize() throws Throwable Called by the garbage collector on an object when garbage collection determines that there are no more references to the object •public String toString() Returns a string representation of the object. 2016 Winter
  • 4. To reduce the complexity and simplify the language, multiple inheritance is NOT supported in Java. 2016 Winter
  • 5. Vehicle.java Car.java Truck.java 2016 Winter Folder  Lab4 Lab4 Examples Inheritance
  • 6. • Any class containing an abstract method is an abstract class • You must declare the class with the keyword abstract: abstract class MyClass {...} • An abstract class is incomplete – It has “missing” method bodies • You cannot instantiate (create a new instance of) an abstract class. 2016 Winter
  • 7. 2016 Winter An interface is a way to describe what classes should do, without specifying how they should do it. It’s not a class but a set of requirements for classes that want to conform to the interface, for example; public interface Comparable { int compareTo(Object otherObject); } This requires that any class implementing the Comparable interface contains a compareTo method, and this method must take an Object parameter and return an integer. Folder  Lab4 Lab4 Examples Interface
  • 8. • Why bother introducing two concepts: abstract class and interface? abstract class Comparable { public abstract int compareTo (Object otherObject); } public class Employee extends Comparable { pulibc int compareTo(Object otherObject) { . . . } } public interface Comparable { int compareTo (Object otherObject) } public class Employee implements Comparable { public int compareTo (Object otherObject) { . . . } } • A class can only extend a single abstract class, but it can implement as many interfaces as it wants • An abstract class can have a partial implementation, protected parts, static methods and so on, while interfaces are limited to public constants and public methods with no implementation. 2016 Winter
  • 10.  An option pane is a simple dialog box for graphical input/output • Advantages: – simple – flexible (in some ways) – looks better than printing out to the console • Disadvantages: – created with static methods; not very object-oriented – not very powerful (just simple dialog boxes) 2016 Winter
  • 11. • public static void showMessageDialog( Component parent, Object message) Displays a message on a dialog with an OK button. • public static int showConfirmDialog( Component parent, Object message) Displays a message and list of choices Yes, No, Cancel • public static String showInputDialog( Component parent, Object message) Displays a message and text field for input, and returns the value entered as a String. 2016 Winter
  • 12. • showMessageDialog is analogous to System.out.println for displaying a simple message import javax.swing.*; public class Main { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "How's the weather?"); JOptionPane.showMessageDialog(null, "Second message"); } } 2016 Winter Folder  Lab4 Lab4 Examples JOptionPane
  • 13. • showConfirmDialog analogous to a System.out.print that prints a question, then reading an input value from the user (can only be one of the provided choices) import javax.swing.*; public class Main { public static void main(String[] args) { int choice = JOptionPane.showConfirmDialog(null, "Erase your hard disk?"); if (choice == JOptionPane.YES_OPTION) { JOptionPane.showMessageDialog(null, "Disk erased!"); } else { JOptionPane.showMessageDialog(null, "Cancelled."); } } } 2016 Winter Folder  Lab4 Lab4 Examples JOptionPane
  • 14. • showInputDialog is analogous to a System.out.print that prints a question, then reading an input value from the user (can be any value) import javax.swing.*; public class Main { public static void main(String[] args) { String name = JOptionPane.showInputDialog(null, "What's yer name, pardner?"); JOptionPane.showMessageDialog(null, "Yeehaw, " + name); } } 2016 Winter Folder Lab4 Lab4 Examples JOptionPane
  • 15. Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs. Swing was developed to provide a more sophisticated set of GUI components than the earlier Abstract Window Toolkit (AWT). 2016 Winter
  • 16. JFrame: a heavy-weight container used as the top-level window. JPanel: a light-weight container used to organize GUI components. 2016 Winter
  • 18. 2016 Winter • The game Puzzler consists of a 7 × 7 board. Initially, all the cells are filled with marbles from one to five available colors. • When the user clicks on a cell for the first time, the cell and all the adjacent cells of the same color are selected. The marbles are gray to indicate this state of the game. • When the user clicks a second time on a selected cell, all the selected cells vanish. Marbles fall from top to bottom, and left to right, in order to fill the empty spaces. • To win the game, the user must make all the marbles vanish. Click on a Yellow marble Click again ! Folder  Lab4 Lab4 Examples Puzzle
  • 19. You can clearly see the important role of inheritance and interface for this game. Each of the three classes is derived from an existing class. 2016 Winter