SlideShare a Scribd company logo
1 of 20
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

More Related Content

What's hot

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-2Nafis Ahmed
 
Knolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in ScalaKnolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in ScalaAyush 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 ScalaAyush Mishra
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in ScalaAyush Mishra
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin 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 structuresagorolabs
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in JavaErhan Bagdemir
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and OverridingMichael 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 ScalaRahul 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 overridingPinky Anaya
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator OverloadingMichael Heron
 

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
 
Knolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in ScalaKnolx Session: Introducing Extractors in Scala
Knolx Session: Introducing Extractors in Scala
 
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
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Introducing Pattern Matching in Scala
 Introducing Pattern Matching  in Scala Introducing Pattern Matching  in Scala
Introducing Pattern Matching in Scala
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
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
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
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
 
Quick Scala
Quick ScalaQuick Scala
Quick Scala
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
#_ varible function
#_ varible function #_ varible function
#_ varible function
 
Variable
VariableVariable
Variable
 
2CPP13 - Operator Overloading
2CPP13 - Operator Overloading2CPP13 - Operator Overloading
2CPP13 - Operator Overloading
 

Similar to Java Tutorial Lab 4

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 TECHNIQUEVinishA23
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1mohamedsamyali
 
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
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ ComparatorSean McElrath
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingMH Abid
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.pptMikeAdva
 
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 interfacesDevaKumari Vijay
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorialDima 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, & StringsBlue Elephant Consulting
 
Interfaces.ppt
Interfaces.pptInterfaces.ppt
Interfaces.pptVarunP31
 
Unit3 packages & interfaces
Unit3 packages & interfacesUnit3 packages & interfaces
Unit3 packages & interfacesKalai Selvi
 

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
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
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...
 
Java mcq
Java mcqJava mcq
Java mcq
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Comparable/ Comparator
Comparable/ ComparatorComparable/ Comparator
Comparable/ Comparator
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Oop java
Oop javaOop java
Oop java
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Unit3 part3-packages and interfaces
Unit3 part3-packages and interfacesUnit3 part3-packages and interfaces
Unit3 part3-packages and interfaces
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
 
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
 
Interfaces .ppt
Interfaces .pptInterfaces .ppt
Interfaces .ppt
 
Interfaces.ppt
Interfaces.pptInterfaces.ppt
Interfaces.ppt
 
Unit3 packages & interfaces
Unit3 packages & interfacesUnit3 packages & interfaces
Unit3 packages & interfaces
 

More from Berk Soysal

Guest author manual
Guest author manualGuest author manual
Guest author manualBerk 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 channelsBerk Soysal
 
Biomedical project report detecting emg noise
Biomedical project report detecting emg noiseBiomedical project report detecting emg noise
Biomedical project report detecting emg noiseBerk 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 9Berk Soysal
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8Berk Soysal
 

More from Berk Soysal (6)

Guest author manual
Guest author manualGuest author manual
Guest author manual
 
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
 
Biomedical project report detecting emg noise
Biomedical project report detecting emg noiseBiomedical project report detecting emg noise
Biomedical project report detecting emg noise
 
Self Evaluation Test
Self Evaluation Test Self Evaluation Test
Self Evaluation Test
 
Java Tutorial Lab 9
Java Tutorial Lab 9Java Tutorial Lab 9
Java Tutorial Lab 9
 
Java Tutorial Lab 8
Java Tutorial Lab 8Java Tutorial Lab 8
Java Tutorial Lab 8
 

Recently uploaded

Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 

Recently uploaded (20)

Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 

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