0% found this document useful (0 votes)
33 views

Java - Practica

This document contains code examples demonstrating access modifiers in Java. It includes code for a package, two classes using private access, and a subclass extending an abstract class. The code calculates the perimeter of a square by getting the side length from a text field, creating a Square object, setting its side, and returning the calculated perimeter.

Uploaded by

Nacion xs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Java - Practica

This document contains code examples demonstrating access modifiers in Java. It includes code for a package, two classes using private access, and a subclass extending an abstract class. The code calculates the perimeter of a square by getting the side length from a text field, creating a Square object, setting its side, and returning the calculated perimeter.

Uploaded by

Nacion xs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

UNACH

FACULTAD DE INGENIERÍA
PROGRAMACIÓN EN JAVA Y LAB.

Programación En Java Y Lab.

NOMBRE: Daniel Patricio Yautibug PRACTICA NO: 04

CARRERA: Electrónica y Telecomunicaciones FECHA: 23-10-2019

SEMESTRE: Séptimo

JAVA - MODIFICADORES DE ACCESO

1.- CODIGO

CODIGO 1 - PAQUETE
package practica_4;
import fiuras.telec.edu.cuadrado;
public class Practica_4 {
public static void main(String[] args) {
new inicio().setVisible(true);
} }

CODIGO 2 – CLASE 1
private void jbtCalcularActionPerformed(java.awt.event.ActionEvent evt) {
cuadrado c =new cuadrado();
c.setLado(Integer.parseInt(jtfLado.getText()));
jtfPerimetro.setText(String.valueOf(c.perimetro()));
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {

pág. 1
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(inicio.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(inicio.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(inicio.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(inicio.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new inicio().setVisible(true);
}
});
}

CODIGO 3 – CLASE 2
package fiuras.telec.edu;
public abstract class figura {
private String color;
public void setColor (String cl){
this.color=cl; }
public String getColor(){
return color;}
public abstract int perimetro();
}

CODIGO 4 – CLASE 3
package fiuras.telec.edu;
public class cuadrado extends figura{
private int lado;
public void setLado (int ld){
this.lado=ld;}
public int getLado(){
return lado;}
public int perimetro(){
return lado*4;}
}

2.- INTERFAS

pág. 2
pág. 3

You might also like