SlideShare a Scribd company logo
http://sitedoph.com.br/
Sobrescrita e Sobrecarga
package ph.sitedo.certificacao.sobrescrita_sobrecarga;
public class Cachorro extends Mamifero
implements Domesticavel {
@Override
public Cachorro(){
super();
}
public void comer() {
System.out.println("Comendo como um Cachorro");
}
public boolean domestica() {
return true;
}
}
package ph.sitedo.certificacao.sobrescrita_sobrecarga;
public class A {
public A() {
}
}
class B extends A {
public B() {
}
public B(String string) {
}
public B(Long longo) {
}
}
public class A {
public int fazAlgo() {
return 1;
}
}
class B extends A {
public int fazAlgo() {
return 2;
}
public int fazAlgo(long l) {
return (int) l;
}
public int fazAlgo(String s) {
return new Integer(s);
}
}
public class A { public int fazAlgo() {return 1;} }
class B extends A {
public int fazAlgo() {
return 2;
}
public int fazAlgo(long l) {
return (int) l;
}
}
class A1 {
A1 get() { return this; }
}
class B1 extends A1 {
B1 get() {
return this;
}
void message() {
System.out.println("Retorno Covariante");
}
public static void main(String args[]) {
new B1().get().message();
}
}
class A1 {
int get() {
return 1;
}
}
class B1 extends A1 {
long get() {
return 1L;
}
}
class A1 {
public int get() {
return 1;
}
}
class B1 extends A1 {
protected int get() {
return 1;
}
}
class A1 {
protected int get() {
return 1;
}
}
class B1 extends A1 {
public int get() {
return 1;
}
}
class A1 {
int get() throws IOException {
return 1;
}
}
class B1 extends A1 {
int get() throws IOException,
ParseException {
return 1;
}
}
class A1 {
int get() throws NumberFormatException {
return 1;
}
}
class B1 extends A1 {
int get() throws Exception {
return 1;
}
}
class A1 {
private int get()
throws NumberFormatException {
return 1;
}
}
class B1 extends A1 {
int get() throws Exception {
return 1;
}
}
import java.io.FileNotFoundException;
import java.nio.file.NoSuchFileException;
class A1 {
int get() throws FileNotFoundException,
NoSuchFileException {
return 1;
}
}
class B1 extends A1 {
int get() throws FileNotFoundException {
return 1;
}
}
class A1 {
int get() throws Exception {
return 1;
}
}
class B1 extends A1 {
int get() throws IOException {
return 1;
}
}
class A1 {
int get() throws Exception {
return 1;
}
}
class B1 extends A1 {
int get() throws NumberFormatException {
return 1;
}
}
class A1 {
int get() {
return 1;
}
long get() {
return 1L;
}
}
class A1 {
int get() {
return 1;
}
long get(long numero) {
return numero;
}
}
class A1 {
public int get() throws IOException{
return 1;
}
private long get(long numero) {
return numero;
}
String get(String numero) throws RuntimeException{
return numero;
}
protected double get(double numero) {
return numero;
}
}
public class TestClass {
public static void main(String args[]) {
A o1 = new C();
System.out.println(o1.i);
System.out.println(o1.m1());
System.out.println(((A) o1).i);
System.out.println(((A) o1).m1());
System.out.println(((B) o1).i);
System.out.println(((B) o1).m1());
System.out.println(((C) o1).i);
System.out.println(((C) o1).m1());
}
}
class A {
int i = 10;
int m1() {
return i;
}
}
class B extends A {
int i = 20;
int m1() {
return i;
}
}
class C extends B {
int i = 30;
int m1() {
return i;
}
}
10
30
10
30
20
30
30
30
public class TestClass {
public static void main(String args[]) {
A o1 = new C();
System.out.println(o1.i);
System.out.println(o1.m1());
System.out.println(((A) o1).i);
System.out.println(((A) o1).m1());
System.out.println(((B) o1).i);
System.out.println(((B) o1).m1());
System.out.println(((C) o1).i);
System.out.println(((C) o1).m1());
}
}
class A {
int i = 10;
int m1() {
return i;
}
}
class B extends A {
int i = 20;
int m1() {
return i;
}
}
class C extends B {
int i = 30;
int m1() {
return i;
}
}
10
30
10
30
20
30
30
30
public class TestClass {
public static void main(String args[]) {
A o1 = new B();
System.out.println(o1.i);
System.out.println(o1.m1());
System.out.println(((A) o1).i);
System.out.println(((A) o1).m1());
System.out.println(((B) o1).i);
System.out.println(((B) o1).m1());
}
}
class A {
int i = 10;
int m1() {
i++;
return i;
}
}
class B extends A {
int i = 20;
int m1() {
i++;
return i;
}
}
10
21
10
22
22
23
http://sitedoph.com.br/
Sobrecarga e Sobrescrita - Preparatório Certificação - OCAJP7 - Aula 2 - F

More Related Content

What's hot

Clang-tidy: путешествие внутрь AST C++
Clang-tidy: путешествие внутрь AST C++Clang-tidy: путешествие внутрь AST C++
Clang-tidy: путешествие внутрь AST C++
corehard_by
 
Антон Полухин. C++17
Антон Полухин. C++17Антон Полухин. C++17
Антон Полухин. C++17
Sergey Platonov
 
Java весна 2013 лекция 7
Java весна 2013 лекция 7Java весна 2013 лекция 7
Java весна 2013 лекция 7Technopark
 
Java весна 2013 лекция 6
Java весна 2013 лекция 6Java весна 2013 лекция 6
Java весна 2013 лекция 6Technopark
 
An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]
Eleanor McHugh
 
Шаблоны проектирования 2
Шаблоны проектирования 2Шаблоны проектирования 2
Шаблоны проектирования 2
Constantin Kichinsky
 
Javascrpt arale
Javascrpt araleJavascrpt arale
Javascrpt araleAlipay
 
Java
JavaJava
Java & le pattern matching
Java & le pattern matchingJava & le pattern matching
Java & le pattern matching
Didier Plaindoux
 
変態的PHPフレームワーク rhaco
変態的PHPフレームワーク rhaco変態的PHPフレームワーク rhaco
変態的PHPフレームワーク rhaco
makoto tsuyuki
 
Membuat program aplikasi kalkulator sederrhana dengan delphi
Membuat program aplikasi kalkulator sederrhana dengan delphiMembuat program aplikasi kalkulator sederrhana dengan delphi
Membuat program aplikasi kalkulator sederrhana dengan delphi
Muhammad Najamuddin Jeneponto
 
Looping
LoopingLooping
LoopingThryo
 
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Loïc Knuchel
 
Evaluacion
EvaluacionEvaluacion
Evaluacion
jbersosa
 
โปรแกรมย่อยและฟังก์ชันมาตรฐาน
โปรแกรมย่อยและฟังก์ชันมาตรฐานโปรแกรมย่อยและฟังก์ชันมาตรฐาน
โปรแกรมย่อยและฟังก์ชันมาตรฐานknangsmiley
 
Boost.勉強会#4 Boost.Proto
Boost.勉強会#4 Boost.ProtoBoost.勉強会#4 Boost.Proto
Boost.勉強会#4 Boost.Proto
fjnl
 

What's hot (20)

Clang-tidy: путешествие внутрь AST C++
Clang-tidy: путешествие внутрь AST C++Clang-tidy: путешествие внутрь AST C++
Clang-tidy: путешествие внутрь AST C++
 
week-24x
week-24xweek-24x
week-24x
 
Антон Полухин. C++17
Антон Полухин. C++17Антон Полухин. C++17
Антон Полухин. C++17
 
Java весна 2013 лекция 7
Java весна 2013 лекция 7Java весна 2013 лекция 7
Java весна 2013 лекция 7
 
Librerias de c++
Librerias de c++Librerias de c++
Librerias de c++
 
Taller de string(java)
Taller de string(java)Taller de string(java)
Taller de string(java)
 
Java весна 2013 лекция 6
Java весна 2013 лекция 6Java весна 2013 лекция 6
Java весна 2013 лекция 6
 
An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]An introduction to functional programming with Go [redux]
An introduction to functional programming with Go [redux]
 
Шаблоны проектирования 2
Шаблоны проектирования 2Шаблоны проектирования 2
Шаблоны проектирования 2
 
Javascrpt arale
Javascrpt araleJavascrpt arale
Javascrpt arale
 
Java
JavaJava
Java
 
Java & le pattern matching
Java & le pattern matchingJava & le pattern matching
Java & le pattern matching
 
All set1
All set1All set1
All set1
 
変態的PHPフレームワーク rhaco
変態的PHPフレームワーク rhaco変態的PHPフレームワーク rhaco
変態的PHPフレームワーク rhaco
 
Membuat program aplikasi kalkulator sederrhana dengan delphi
Membuat program aplikasi kalkulator sederrhana dengan delphiMembuat program aplikasi kalkulator sederrhana dengan delphi
Membuat program aplikasi kalkulator sederrhana dengan delphi
 
Looping
LoopingLooping
Looping
 
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
Comprendre la programmation fonctionnelle, Blend Web Mix le 02/11/2016
 
Evaluacion
EvaluacionEvaluacion
Evaluacion
 
โปรแกรมย่อยและฟังก์ชันมาตรฐาน
โปรแกรมย่อยและฟังก์ชันมาตรฐานโปรแกรมย่อยและฟังก์ชันมาตรฐาน
โปรแกรมย่อยและฟังก์ชันมาตรฐาน
 
Boost.勉強会#4 Boost.Proto
Boost.勉強会#4 Boost.ProtoBoost.勉強会#4 Boost.Proto
Boost.勉強会#4 Boost.Proto
 

More from Paulo Henrique Lerbach Rodrigues

Tipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - E
Tipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - ETipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - E
Tipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - E
Paulo Henrique Lerbach Rodrigues
 
Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...
Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...
Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...
Paulo Henrique Lerbach Rodrigues
 
Membros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - D
Membros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - DMembros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - D
Membros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - D
Paulo Henrique Lerbach Rodrigues
 
Escopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - B
Escopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - BEscopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - B
Escopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - B
Paulo Henrique Lerbach Rodrigues
 
Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0
Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0
Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0
Paulo Henrique Lerbach Rodrigues
 
Interfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - C
Interfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - CInterfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - C
Interfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - C
Paulo Henrique Lerbach Rodrigues
 
Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...
Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...
Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...
Paulo Henrique Lerbach Rodrigues
 

More from Paulo Henrique Lerbach Rodrigues (7)

Tipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - E
Tipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - ETipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - E
Tipos Primitivos - Preparatório Certificação - OCAJP7 - Aula 2 - E
 
Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...
Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...
Sobrecarga e invocação de métodos - Preparatório Certificação - OCAJP7 - Aula...
 
Membros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - D
Membros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - DMembros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - D
Membros da Classe - Preparatório Certificação - OCAJP7 - Aula 2 - D
 
Escopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - B
Escopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - BEscopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - B
Escopos e Modificadores - Preparatório Certificação - OCAJP7 - Aula 1 - B
 
Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0
Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0
Sobre a Certificação - Preparatório Certificação - OCAJP7 - Aula 1 - 0
 
Interfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - C
Interfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - CInterfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - C
Interfaces e Polimorfismo - Preparatório Certificação - OCAJP7 - Aula 1 - C
 
Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...
Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...
Revisão de Classes e arquivos .java - Preparatório Certificação - OCAJP7 - Au...
 

Sobrecarga e Sobrescrita - Preparatório Certificação - OCAJP7 - Aula 2 - F

  • 1.
  • 4. package ph.sitedo.certificacao.sobrescrita_sobrecarga; public class Cachorro extends Mamifero implements Domesticavel { @Override public Cachorro(){ super(); } public void comer() { System.out.println("Comendo como um Cachorro"); } public boolean domestica() { return true; } }
  • 5. package ph.sitedo.certificacao.sobrescrita_sobrecarga; public class A { public A() { } } class B extends A { public B() { } public B(String string) { } public B(Long longo) { } }
  • 6. public class A { public int fazAlgo() { return 1; } } class B extends A { public int fazAlgo() { return 2; } public int fazAlgo(long l) { return (int) l; } public int fazAlgo(String s) { return new Integer(s); } }
  • 7. public class A { public int fazAlgo() {return 1;} } class B extends A { public int fazAlgo() { return 2; } public int fazAlgo(long l) { return (int) l; } }
  • 8. class A1 { A1 get() { return this; } } class B1 extends A1 { B1 get() { return this; } void message() { System.out.println("Retorno Covariante"); } public static void main(String args[]) { new B1().get().message(); } }
  • 9. class A1 { int get() { return 1; } } class B1 extends A1 { long get() { return 1L; } }
  • 10. class A1 { public int get() { return 1; } } class B1 extends A1 { protected int get() { return 1; } }
  • 11. class A1 { protected int get() { return 1; } } class B1 extends A1 { public int get() { return 1; } }
  • 12.
  • 13. class A1 { int get() throws IOException { return 1; } } class B1 extends A1 { int get() throws IOException, ParseException { return 1; } }
  • 14. class A1 { int get() throws NumberFormatException { return 1; } } class B1 extends A1 { int get() throws Exception { return 1; } }
  • 15. class A1 { private int get() throws NumberFormatException { return 1; } } class B1 extends A1 { int get() throws Exception { return 1; } }
  • 16. import java.io.FileNotFoundException; import java.nio.file.NoSuchFileException; class A1 { int get() throws FileNotFoundException, NoSuchFileException { return 1; } } class B1 extends A1 { int get() throws FileNotFoundException { return 1; } }
  • 17. class A1 { int get() throws Exception { return 1; } } class B1 extends A1 { int get() throws IOException { return 1; } }
  • 18. class A1 { int get() throws Exception { return 1; } } class B1 extends A1 { int get() throws NumberFormatException { return 1; } }
  • 19. class A1 { int get() { return 1; } long get() { return 1L; } }
  • 20. class A1 { int get() { return 1; } long get(long numero) { return numero; } }
  • 21. class A1 { public int get() throws IOException{ return 1; } private long get(long numero) { return numero; } String get(String numero) throws RuntimeException{ return numero; } protected double get(double numero) { return numero; } }
  • 22. public class TestClass { public static void main(String args[]) { A o1 = new C(); System.out.println(o1.i); System.out.println(o1.m1()); System.out.println(((A) o1).i); System.out.println(((A) o1).m1()); System.out.println(((B) o1).i); System.out.println(((B) o1).m1()); System.out.println(((C) o1).i); System.out.println(((C) o1).m1()); } } class A { int i = 10; int m1() { return i; } } class B extends A { int i = 20; int m1() { return i; } } class C extends B { int i = 30; int m1() { return i; } } 10 30 10 30 20 30 30 30
  • 23. public class TestClass { public static void main(String args[]) { A o1 = new C(); System.out.println(o1.i); System.out.println(o1.m1()); System.out.println(((A) o1).i); System.out.println(((A) o1).m1()); System.out.println(((B) o1).i); System.out.println(((B) o1).m1()); System.out.println(((C) o1).i); System.out.println(((C) o1).m1()); } } class A { int i = 10; int m1() { return i; } } class B extends A { int i = 20; int m1() { return i; } } class C extends B { int i = 30; int m1() { return i; } } 10 30 10 30 20 30 30 30
  • 24. public class TestClass { public static void main(String args[]) { A o1 = new B(); System.out.println(o1.i); System.out.println(o1.m1()); System.out.println(((A) o1).i); System.out.println(((A) o1).m1()); System.out.println(((B) o1).i); System.out.println(((B) o1).m1()); } } class A { int i = 10; int m1() { i++; return i; } } class B extends A { int i = 20; int m1() { i++; return i; } } 10 21 10 22 22 23