This document provides an overview of key concepts in Ruby including variables, methods, classes, modules, inheritance and scope. It discusses local variables, instance variables, class variables and global variables. It explains how methods are defined and called in Ruby. It describes classes and modules, and how modules can be mixed into classes. The document also covers inheritance, constants, self, and singleton methods. It provides details on variable scope and how Ruby determines an identifier is a variable, keyword or method call.
Hlutbundin forritun er öflug leið til að búa til hugbúnað. Hins vegar er auðvelt að gleyma eiginleikum hlutbundinna mála. Í þessum fyrri hluta um þetta efni munum við rifja upp hugtök eins og encapsulation, skil og polymorphma. Við munum líka skoða nokkur prinsipp eins og Separtaion of Concern (SoC).
Í þessu fyrirlestri mun ég upplýsa leyndarmál sem aðeins góðir forritarar vita.
This document provides an overview of inheritance in object-oriented programming. It defines inheritance as a child class automatically inheriting variables and methods from its parent class. Benefits include reusability, where behaviors are defined once in the parent class and shared by all subclasses. The document discusses how to derive a subclass using the extends keyword, what subclasses can do with inherited and new fields and methods, and how constructors are called following the constructor calling chain. It also covers overriding and hiding methods and fields, type casting between subclasses and superclasses, and final classes and methods that cannot be extended or overridden.
The document discusses inheritance in Java. It defines inheritance as a process where one class acquires properties of another class. The class that inherits properties is called a subclass, and the class whose properties are inherited is called a superclass. In Java, a subclass can only inherit from one superclass (single inheritance). The extends keyword is used for inheritance. The document then discusses what can be done in subclasses, such as overriding and overloading methods, and polymorphism. It also covers abstract classes, interfaces, and casting objects.
Object oriented programming uses concepts like encapsulation, inheritance and polymorphism to create robust and secure code. The key concepts are:
1. Encapsulation and data abstraction which group data and functions that work on that data.
2. Inheritance allows code reusability through parent-child class relationships in multilevel and multiple inheritance.
3. Polymorphism enables one interface and different actions through inheritance.
OCA Java SE 8 Exam Chapter 5 Class Designİbrahim Kürce
Inheritance is the process by which the new child subclass automatically includes any public or protected primitives, objects, or methods defined in the parent class.
We refer to any class that inherits from another class as a child class, or a descendent of that class.
We refer to the class that the child inherits from as the parent class, or an ancestor of the class.
Inheritance in Java beginner to advance with examples.pptxnaeemcse
Dive into the world of Java Inheritance and discover how it forms the backbone of robust and scalable code architecture. Learn how this powerful object-oriented programming concept allows you to effortlessly reuse and extend existing code, promoting a modular and maintainable design. Whether you're a novice or a seasoned developer, grasp the key principles of inheritance and elevate your Java programming skills. Join us on this journey to empower your code with the inheritance advantage, setting the stage for efficient development and enhanced software flexibility. Don't miss out on this essential building block for creating elegant and efficient Java applications!Unlock the potential of Java Inheritance with a concise exploration of single, multiple, multilevel, and hierarchical types. Discover how each type enhances code structure and flexibility. Elevate your Java skills by understanding the nuances of inheritance, optimizing code for efficiency and maintainability. Join us on this journey of code mastery and harness the diverse power of inheritance in your Java projects.
This document provides an overview of Java fundamentals including classes, objects, encapsulation, abstraction, inheritance, polymorphism and other core OOP concepts. Key points covered include:
- Classes contain variable declarations and method definitions while objects have state, behavior and identity.
- Encapsulation is achieved by declaring class variables as private and providing public get and set methods.
- Abstraction hides certain details and shows only essential information to the user using abstract classes and interfaces.
- Inheritance allows classes to extend functionality from other classes in a hierarchical manner to achieve code reuse.
- Polymorphism allows a single action to be performed in different ways depending on the object used.
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
OOPS and its application in Java, Super class AND This Keyword,Java Bean, POJO ,Memory management in Java ,Packages ,Miscellaneous (Var-Args, toString(), Double equals operator(==))
This 5-day Java workshop covers object-oriented programming (OOP) inheritance. The key concepts discussed include the four pillars of OOP - encapsulation, abstraction, inheritance, and polymorphism. Inheritance allows classes to extend existing classes to share common attributes and methods, while also adding new unique functionality. The workshop provides examples of defining parent and child classes, using inheritance, overriding methods, and casting between classes. Resources for further learning about Java and OOP are also listed.
An object contains both data and methods that manipulate that data. The data represent the state of the object. Classes describe objects by defining their fields and methods. Objects inherit fields and methods from their superclass and belong to a class. Constructors are used to create objects and initialize their fields. Access control determines which fields and methods are accessible to other classes.
Object Oriented Programming is revisited. It is assumed that students know OO languages so this is more of a review. We will cover concepts such as encapsulation, interfaces and polymorphism. These are important concepts that students must understand in order to write flexible and lasting code. We look at several design principles.
We also look at software design and take an example from a video games.
In this lecture we will also reveal the secret of programming which all good programmers must know.
This class is abstract but it does not provide implementation of abstract method print(). An abstract class must be subclassed and the abstract methods must be implemented in the subclass. We cannot create an object of an abstract class directly, it has to be through its concrete subclass.
The document provides an overview of lecture 03 on objects and classes in Java, including reviewing basic concepts, declaring and using classes, implementing inheritance, and discussing abstract classes and interfaces. It also includes examples of declaring classes, using constructors and methods, and implementing inheritance and polymorphism. The lecture aims to help students understand object-oriented concepts in Java like classes, objects, inheritance and polymorphism.
This chapter discusses inheritance, polymorphism, abstract classes, interfaces, and composition in Java. It covers key concepts like subclasses inheriting and overriding methods from superclasses, polymorphism allowing subclasses to be treated as superclasses, abstract classes containing abstract methods that subclasses must implement, interfaces defining common behaviors without implementations, and composition representing "has-a" relationships between classes. The chapter provides examples and explains how to apply these object-oriented programming principles in Java.
An object has both data and methods that manipulate that data. The data represents the state of the object. A class describes the fields and methods of objects that belong to that class. Classes form a hierarchy where subclasses inherit fields and methods from their parent classes. Objects must be created from their classes using constructors before their fields and methods can be accessed.
An object has both data fields that represent its state and methods that can manipulate that state. A class defines the fields and methods for any objects instantiated from that class. Constructors are used to create objects from classes and ensure their fields are initialized properly. Inheritance allows subclasses to inherit fields and methods from their parent classes while also adding their own fields and methods.
An object contains both data and methods that manipulate that data. The data represents the state of the object. Classes describe objects by defining their fields and methods. Objects inherit fields and methods from their superclass. To create an object, the appropriate constructor must be called using the new keyword. Access control determines which fields and methods are accessible to other classes.
This chapter discusses decision making, object-oriented fundamentals, inner classes, and exception handling in Java. It describes the use of if and switch statements for decision making. It also covers access specifiers, encapsulation, inheritance, polymorphism, abstract classes, interfaces, inner classes, and exceptions.
The document provides definitions and explanations of various object-oriented programming concepts in Delphi such as classes, objects, visibility of class members, inheritance, abstract classes, interfaces, constructors, virtual functions, polymorphism, late binding, encapsulation, properties, exceptions handling, and runtime type information (RTTI). It discusses these concepts through questions and answers. Key points covered include the relationship between classes and objects, differences between visibility levels of class members, how inheritance allows the creation of subclasses, rules around abstract classes and methods, limitations of interfaces, how to define and overload constructors and functions, use of virtual functions and polymorphism, and how RTTI is used.
Infocampus Offers best Java training in Bangalore. Infocampus provides java classes with real time practical sessions. We are conducting weekdays and weekend classes and we have good infrastructure. Easy installments. 100% Placement assistance. Experienced trainers. If you are looking for training with placement assistance please do reach us @ 9738001024.visit: http://infocampus.co.in/java-training-bangalore.html
This document contains instructions and questions for COP2800 Midterm Exam #2 Spring 2013. Students are allowed to bring a handwritten crib sheet, basic calculator, pen/pencil, and eraser. All other belongings and electronics must be put away. The exam contains 4 regular questions and 1 extra credit question testing concepts like inheritance, polymorphism, abstract classes, arrays, and array lists in Java. Students must show their work for calculation questions.
This document presents an overview of object-oriented PHP. It discusses key concepts like classes, objects, inheritance, interfaces and magic methods. It provides examples of how to define classes and objects in PHP and utilize various OOP features like visibility, abstraction, static methods and autoloading. The goal is to help PHP programmers understand object-oriented programming principles and their implementation in PHP.
This document summarizes key concepts from a coding lesson including hashes, classes, variables scopes (global, instance, class), inheritance, and overriding methods. It discusses defining classes, creating objects, using methods, and accessing variables. Inheritance allows a class to inherit attributes and behaviors from a parent class. Derived classes can override methods from the parent class. The super keyword can call the parent method implementation.
Inheritance allows classes to extend existing classes, reusing and building upon their attributes and behaviors. This supports polymorphism by allowing parent and child classes to be treated the same when interacting with their common attributes and methods. Well-known inheritance hierarchies include shapes (like rectangles and circles) inheriting from a parent shape class, or employees inheriting from a main employee class. Inheritance promotes code reuse and flexibility.
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
OOPS and its application in Java, Super class AND This Keyword,Java Bean, POJO ,Memory management in Java ,Packages ,Miscellaneous (Var-Args, toString(), Double equals operator(==))
This 5-day Java workshop covers object-oriented programming (OOP) inheritance. The key concepts discussed include the four pillars of OOP - encapsulation, abstraction, inheritance, and polymorphism. Inheritance allows classes to extend existing classes to share common attributes and methods, while also adding new unique functionality. The workshop provides examples of defining parent and child classes, using inheritance, overriding methods, and casting between classes. Resources for further learning about Java and OOP are also listed.
An object contains both data and methods that manipulate that data. The data represent the state of the object. Classes describe objects by defining their fields and methods. Objects inherit fields and methods from their superclass and belong to a class. Constructors are used to create objects and initialize their fields. Access control determines which fields and methods are accessible to other classes.
Object Oriented Programming is revisited. It is assumed that students know OO languages so this is more of a review. We will cover concepts such as encapsulation, interfaces and polymorphism. These are important concepts that students must understand in order to write flexible and lasting code. We look at several design principles.
We also look at software design and take an example from a video games.
In this lecture we will also reveal the secret of programming which all good programmers must know.
This class is abstract but it does not provide implementation of abstract method print(). An abstract class must be subclassed and the abstract methods must be implemented in the subclass. We cannot create an object of an abstract class directly, it has to be through its concrete subclass.
The document provides an overview of lecture 03 on objects and classes in Java, including reviewing basic concepts, declaring and using classes, implementing inheritance, and discussing abstract classes and interfaces. It also includes examples of declaring classes, using constructors and methods, and implementing inheritance and polymorphism. The lecture aims to help students understand object-oriented concepts in Java like classes, objects, inheritance and polymorphism.
This chapter discusses inheritance, polymorphism, abstract classes, interfaces, and composition in Java. It covers key concepts like subclasses inheriting and overriding methods from superclasses, polymorphism allowing subclasses to be treated as superclasses, abstract classes containing abstract methods that subclasses must implement, interfaces defining common behaviors without implementations, and composition representing "has-a" relationships between classes. The chapter provides examples and explains how to apply these object-oriented programming principles in Java.
An object has both data and methods that manipulate that data. The data represents the state of the object. A class describes the fields and methods of objects that belong to that class. Classes form a hierarchy where subclasses inherit fields and methods from their parent classes. Objects must be created from their classes using constructors before their fields and methods can be accessed.
An object has both data fields that represent its state and methods that can manipulate that state. A class defines the fields and methods for any objects instantiated from that class. Constructors are used to create objects from classes and ensure their fields are initialized properly. Inheritance allows subclasses to inherit fields and methods from their parent classes while also adding their own fields and methods.
An object contains both data and methods that manipulate that data. The data represents the state of the object. Classes describe objects by defining their fields and methods. Objects inherit fields and methods from their superclass. To create an object, the appropriate constructor must be called using the new keyword. Access control determines which fields and methods are accessible to other classes.
This chapter discusses decision making, object-oriented fundamentals, inner classes, and exception handling in Java. It describes the use of if and switch statements for decision making. It also covers access specifiers, encapsulation, inheritance, polymorphism, abstract classes, interfaces, inner classes, and exceptions.
The document provides definitions and explanations of various object-oriented programming concepts in Delphi such as classes, objects, visibility of class members, inheritance, abstract classes, interfaces, constructors, virtual functions, polymorphism, late binding, encapsulation, properties, exceptions handling, and runtime type information (RTTI). It discusses these concepts through questions and answers. Key points covered include the relationship between classes and objects, differences between visibility levels of class members, how inheritance allows the creation of subclasses, rules around abstract classes and methods, limitations of interfaces, how to define and overload constructors and functions, use of virtual functions and polymorphism, and how RTTI is used.
Infocampus Offers best Java training in Bangalore. Infocampus provides java classes with real time practical sessions. We are conducting weekdays and weekend classes and we have good infrastructure. Easy installments. 100% Placement assistance. Experienced trainers. If you are looking for training with placement assistance please do reach us @ 9738001024.visit: http://infocampus.co.in/java-training-bangalore.html
This document contains instructions and questions for COP2800 Midterm Exam #2 Spring 2013. Students are allowed to bring a handwritten crib sheet, basic calculator, pen/pencil, and eraser. All other belongings and electronics must be put away. The exam contains 4 regular questions and 1 extra credit question testing concepts like inheritance, polymorphism, abstract classes, arrays, and array lists in Java. Students must show their work for calculation questions.
This document presents an overview of object-oriented PHP. It discusses key concepts like classes, objects, inheritance, interfaces and magic methods. It provides examples of how to define classes and objects in PHP and utilize various OOP features like visibility, abstraction, static methods and autoloading. The goal is to help PHP programmers understand object-oriented programming principles and their implementation in PHP.
This document summarizes key concepts from a coding lesson including hashes, classes, variables scopes (global, instance, class), inheritance, and overriding methods. It discusses defining classes, creating objects, using methods, and accessing variables. Inheritance allows a class to inherit attributes and behaviors from a parent class. Derived classes can override methods from the parent class. The super keyword can call the parent method implementation.
Inheritance allows classes to extend existing classes, reusing and building upon their attributes and behaviors. This supports polymorphism by allowing parent and child classes to be treated the same when interacting with their common attributes and methods. Well-known inheritance hierarchies include shapes (like rectangles and circles) inheriting from a parent shape class, or employees inheriting from a main employee class. Inheritance promotes code reuse and flexibility.
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Guru
This PRIZ Academy deck walks you step-by-step through Functional Modeling in Action, showing how Subject-Action-Object (SAO) analysis pinpoints critical functions, ranks harmful interactions, and guides fast, focused improvements. You’ll see:
Core SAO concepts and scoring logic
A wafer-breakage case study that turns theory into practice
A live PRIZ Platform demo that builds the model in minutes
Ideal for engineers, QA managers, and innovation leads who need clearer system insight and faster root-cause fixes. Dive in, map functions, and start improving what really matters.
YJIT can make Ruby code run faster, but this is a balancing act, because the JIT compiler itself must consume both memory and CPU cycles to compile and optimize your code while it is running. Furthermore, in large-scale production environments such as those of GitHub, Shopify and Stripe, we end up in a situation where YJIT is compiling the same code over and over again on a very large number of servers, which seems very inefficient.
In this presentation, we will go over the design of ZJIT, a next generation Ruby JIT which aims to save and reuse compiled code between executions. We hope that this will help us eliminate duplicated work while also allowing the compiler to spend more time optimizing code so that we can get better performance.
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...Infopitaara
A Boiler Feed Pump (BFP) is a critical component in thermal power plants. It supplies high-pressure water (feedwater) to the boiler, ensuring continuous steam generation.
⚙️ How a Boiler Feed Pump Works
Water Collection:
Feedwater is collected from the deaerator or feedwater tank.
Pressurization:
The pump increases water pressure using multiple impellers/stages in centrifugal types.
Discharge to Boiler:
Pressurized water is then supplied to the boiler drum or economizer section, depending on design.
🌀 Types of Boiler Feed Pumps
Centrifugal Pumps (most common):
Multistage for higher pressure.
Used in large thermal power stations.
Positive Displacement Pumps (less common):
For smaller or specific applications.
Precise flow control but less efficient for large volumes.
🛠️ Key Operations and Controls
Recirculation Line: Protects the pump from overheating at low flow.
Throttle Valve: Regulates flow based on boiler demand.
Control System: Often automated via DCS/PLC for variable load conditions.
Sealing & Cooling Systems: Prevent leakage and maintain pump health.
⚠️ Common BFP Issues
Cavitation due to low NPSH (Net Positive Suction Head).
Seal or bearing failure.
Overheating from improper flow or recirculation.
its all about Artificial Intelligence(Ai) and Machine Learning and not on advanced level you can study before the exam or can check for some information on Ai for project
Sorting Order and Stability in Sorting.
Concept of Internal and External Sorting.
Bubble Sort,
Insertion Sort,
Selection Sort,
Quick Sort and
Merge Sort,
Radix Sort, and
Shell Sort,
External Sorting, Time complexity analysis of Sorting Algorithms.
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxRishavKumar530754
LiDAR-Based System for Autonomous Cars
Autonomous Driving with LiDAR Tech
LiDAR Integration in Self-Driving Cars
Self-Driving Vehicles Using LiDAR
LiDAR Mapping for Driverless Cars
Passenger car unit (PCU) of a vehicle type depends on vehicular characteristics, stream characteristics, roadway characteristics, environmental factors, climate conditions and control conditions. Keeping in view various factors affecting PCU, a model was developed taking a volume to capacity ratio and percentage share of particular vehicle type as independent parameters. A microscopic traffic simulation model VISSIM has been used in present study for generating traffic flow data which some time very difficult to obtain from field survey. A comparison study was carried out with the purpose of verifying when the adaptive neuro-fuzzy inference system (ANFIS), artificial neural network (ANN) and multiple linear regression (MLR) models are appropriate for prediction of PCUs of different vehicle types. From the results observed that ANFIS model estimates were closer to the corresponding simulated PCU values compared to MLR and ANN models. It is concluded that the ANFIS model showed greater potential in predicting PCUs from v/c ratio and proportional share for all type of vehicles whereas MLR and ANN models did not perform well.
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfMohamedAbdelkader115
Glad to be one of only 14 members inside Kuwait to hold this credential.
Please check the members inside kuwait from this link:
https://www.rics.org/networking/find-a-member.html?firstname=&lastname=&town=&country=Kuwait&member_grade=(AssocRICS)&expert_witness=&accrediation=&page=1
Analysis of reinforced concrete deep beam is based on simplified approximate method due to the complexity of the exact analysis. The complexity is due to a number of parameters affecting its response. To evaluate some of this parameters, finite element study of the structural behavior of the reinforced self-compacting concrete deep beam was carried out using Abaqus finite element modeling tool. The model was validated against experimental data from the literature. The parametric effects of varied concrete compressive strength, vertical web reinforcement ratio and horizontal web reinforcement ratio on the beam were tested on eight (8) different specimens under four points loads. The results of the validation work showed good agreement with the experimental studies. The parametric study revealed that the concrete compressive strength most significantly influenced the specimens’ response with the average of 41.1% and 49 % increment in the diagonal cracking and ultimate load respectively due to doubling of concrete compressive strength. Although the increase in horizontal web reinforcement ratio from 0.31 % to 0.63 % lead to average of 6.24 % increment on the diagonal cracking load, it does not influence the ultimate strength and the load-deflection response of the beams. Similar variation in vertical web reinforcement ratio leads to an average of 2.4 % and 15 % increment in cracking and ultimate load respectively with no appreciable effect on the load-deflection response.
In modern aerospace engineering, uncertainty is not an inconvenience — it is a defining feature. Lightweight structures, composite materials, and tight performance margins demand a deeper understanding of how variability in material properties, geometry, and boundary conditions affects dynamic response. This keynote presentation tackles the grand challenge: how can we model, quantify, and interpret uncertainty in structural dynamics while preserving physical insight?
This talk reflects over two decades of research at the intersection of structural mechanics, stochastic modelling, and computational dynamics. Rather than adopting black-box probabilistic methods that obscure interpretation, the approaches outlined here are rooted in engineering-first thinking — anchored in modal analysis, physical realism, and practical implementation within standard finite element frameworks.
The talk is structured around three major pillars:
1. Parametric Uncertainty via Random Eigenvalue Problems
* Analytical and asymptotic methods are introduced to compute statistics of natural frequencies and mode shapes.
* Key insight: eigenvalue sensitivity depends on spectral gaps — a critical factor for systems with clustered modes (e.g., turbine blades, panels).
2. Parametric Uncertainty in Dynamic Response using Modal Projection
* Spectral function-based representations are presented as a frequency-adaptive alternative to classical stochastic expansions.
* Efficient Galerkin projection techniques handle high-dimensional random fields while retaining mode-wise physical meaning.
3. Nonparametric Uncertainty using Random Matrix Theory
* When system parameters are unknown or unmeasurable, Wishart-distributed random matrices offer a principled way to encode uncertainty.
* A reduced-order implementation connects this theory to real-world systems — including experimental validations with vibrating plates and large-scale aerospace structures.
Across all topics, the focus is on reduced computational cost, physical interpretability, and direct applicability to aerospace problems.
The final section outlines current integration with FE tools (e.g., ANSYS, NASTRAN) and ongoing research into nonlinear extensions, digital twin frameworks, and uncertainty-informed design.
Whether you're a researcher, simulation engineer, or design analyst, this presentation offers a cohesive, physics-based roadmap to quantify what we don't know — and to do so responsibly.
Key words
Stochastic Dynamics, Structural Uncertainty, Aerospace Structures, Uncertainty Quantification, Random Matrix Theory, Modal Analysis, Spectral Methods, Engineering Mechanics, Finite Element Uncertainty, Wishart Distribution, Parametric Uncertainty, Nonparametric Modelling, Eigenvalue Problems, Reduced Order Modelling, ASME SSDM2025
1. CSSE221: Software Dev. Honors Day 6
Announcements
Questions?
Hint on BallWorlds’ changing the x and y coords in
2nd half of lecture today.
2. This week: BallWorlds assignment
Monday:
Intro to UML as a communication tool
Writing methods you don't call
Using this
Tuesday:
Inheritance
Polymorphism
Thursday:
Introducing next week’s assignment
Arrays and ArrayLists
(Using the debugger)
3. Reminder
For the inheritance, polymorphism, and array
groups, you owe me 3 things:
1. Summary
2. Quiz
3. Answer key
4. Inheritance slides
Some material from those produced by Fall
2006-2007 CSSE221 students:
Michael Auchter
Michael Boland
Andrew Hettlinger
5. Inheritance
Objects of different kinds (classes) have their
own unique behavior.
Objects of different kinds often share similar
behavior too.
For example:
Student, Professor, Software Engineer, Chemical
Engineer, Physicist, Guitarist, Drummer
Each has distinct actions to perform, but they also
have many features and behavior in common
6. Why not just copy-and-paste?
Say I have an Employee class and want to
create an HourlyEmployee class that adds
info about wages. Why not copy-and-paste,
then modify?
1. Fixing bugs: what if one were wrong?
2. Maintenance: what if Employee changes?
3. Code-reuse: would code that takes an Employee
as a parameter also take an HourlyEmployee?
7. The Basics of Inheritance
Inheritance allows you to reuse methods that
you’ve already written to create more specialized
versions of a class.
Java keyword: extends.
public class HourlyEmployee extends Employee.
We say that an HourlyEmployee IS-A Employee
Employee is said to be the parent class (or
superclass), and HourlyEmployee is called a child
class (or subclass).
HourlyEmployee receives copies of all of the non-
private methods and variables present in Employee.
8. Your turn
Quiz question: What is the relationship between
a parrot and a bird?
9. Some Key Ideas in Inheritance
Code reuse
Overriding methods
Protected visibility
The “super” keyword
10. Code re-use
The subclass inherits all the public and
protected methods and fields of the superclass.
Constructors are not inherited
Constructors can be invoked by the subclass
Subclass can add new methods and fields.
11. Overriding Methods
DudThatMoves will “extend” Dud
If it defines an act() method with the same
signature that overrides Dud’s method
What do you think happens if our child class
doesn’t override a method in the parent class?
It’s exactly the
same as in the
parent class!
12. Visibility Modifiers
• Public – Accessible by any other class in any package.
• Private – Accessible only within the class.
• Protected – Accessible only by classes within the same
package and any subclasses in other packages.
• (For this reason, some choose not to use protected, but use
private with accessors)
• Default (No Modifier) – Accessible by classes in the
same package but not by classes in other packages.
• Use sparingly!
13. Protected Visibility
Suppose in Dud you defined:
protected int xPos;
Then:
Instances of children inherit this field
(one for each instance)
Children can access/modify the fields
this.xPos in Dud (parent) and this.xPos in
DudThatMoves (child) refer to same value
14. The “super” Keyword
It’s like the word “this,” only “super”:
In a child class, “super” refers to its parent.
Two uses:
1. To call a parent’s method, use super.methodName(…)
2. To call a parent’s constructor, use super(some parameter)
from the child class’ constructor
Reminder, still use this (super not needed) to
access parent’s fields: this.xPos
15. The “super” Keyword
Methods can call super.methodName(…)
To do the work of the parent class method, plus…
Additional work for the child class
public class Workaholic extends Worker {
public void doWork() {
super.doWork();
drinkCoffee();
super.doWork();
}
}
16. The “super” Keyword
Methods can call super.methodName(…)
To do the work of the parent class method, plus…
Additional work for the child class
public class RoseStudent extends Worker {
public void doWork() {
while (!isCollapsed) {
super.doWork();
drinkCoffee();
}
super.doWork();
}
}
17. Rules of using super in constructors
A super(…) call must be the first line of the
code of an object’s constructor if it is to be
used.
Instance variables cannot be passed along with
the super(…) call. Only variables that are
passed to the constructor that calls super may
be passed to super.
18. The this Keyword
1. this.someField and this.someMethod(): nice style
2. this alone is used to represent the whole object: env.addBall(this)
3. this is used to call another constructor inside of a method with
multiple constructors.
public class foo {
private String message;
public foo(){
this(“This foo is saaaaaad.”);
}
public foo(String s){
message = s;
}
}
this has the same restrictions on it as super – that is, it must be the
first thing called in a constructor and it cannot be passed instance
variables.
Therefore, super(…) and this(…) cannot be used in the same
constructor.
19. Final notes
Every object in Java extends java.lang.Object
Don’t have to say it explicitly
This is why every class has a basic toString() method.
What does it mean for a field to be declared final?
Final fields can’t be assigned a new value
Final methods cannot be overridden
Final classes cannot be extended
There is only single inheritance in Java.
Subclass can be derived only from one superclass.
20. Inheritance Basics
(a checklist to which to refer)
Classes extending other classes:
Only have to describe how they are different from parents
Don’t have to repeat methods which are “good enough” in the
parent
Can replace or “extend” any method which isn’t “good enough”
Can access parent’s methods and constrcutors via super.
Can share fields with a parent in a “protected” way (say,
this.xPos)
Only need to declare imports they use (like java.awt.Color)
Don’t have to redeclare interfaces of the parent (like
Drawable)
22. Polymorphism
Polymorphism is the concept of allowing a
reference to a subclass to be used in a place where a
reference to its parent’s class would be acceptable.
An easy and generic example is as follows:
Object o = new Foo();
Since every class extends Object, any object can be
stored in an Object variable.
They just have extra info that can’t be accessed.
Superclass Subclass
23. Example
In the bird and parrot example, consider a bird method:
static void printCall(Bird bird) {
System.out.println(bird.call);
}
Generic: printBirdCall expects a Bird, but any type of
bird is OK.
Cannot write Parrot p = new Bird(); //there’s not
enough info!
However, without casting, b can only use bird methods.
Bird b = new Parrot();
printBirdCall(b)
Parrot p = new Parrot();
printBirdCall(p)
24. Casting and instanceof
If we know that b is a Parrot, we can cast it and use Parrot
methods:
((Parrot)b).speak()
Side note: Ellipse2D.Doubles have x coordinates, Shapes do not:
((Ellipse2D.Double)shape).x += xVelocity;
At runtime, if b is just a Bird, the JVM will throw a
ClassCastException.
To test this, use instanceof:
if (b instanceof Parrot) { ((Parrot)b).speak()) }
25. Late Binding: The Power of
Polymorphism
Hourly Employee h = new HourlyEmployee("Wilma Worker", new
Date("October", 16, 2005), 12.50, 170);
SalariedEmployee s = new SalariedEmployee("Mark Manager",
new Date("June", 4, 2006), 40000);
Employee e = null;
if (getWeekDay().equals(“Saturday”)
e = h;
else
e = s;
System.out.println(e);
When can I tell which value e will have, at compile time or run time?
So Java defers the decision about which version of toString() will be used until
then: it binds the actual method call used as late as possible.
Late Binding is also called dynamic dispatch or dynamic binding.
Note: it uses the most specific version of the method it can.
26. Overriding vs. Overloading
Recall: overriding a method is when a subclass
has method with the same signature (name and
parameter list) as its superclass
Mover’s act() and Bouncer’s act()
Overloading a method is when two methods
have the same name, but different parameter
lists
Arrays.sort(array, begin, end) and Arrays.sort(array)