8. class A{
int x,y;
public void num()
{
System.out.println("x+y="+(x+y));
}
} class B extends A{
}
class run{
public static void main(String[] args)
{
A aa=new A();
B bb=new B();
bb.x=10;
bb.y=20;
bb.num();
} }
•BA
9. xyB.
B
AB
class A{
int x,y;
public void num()
{
System.out.println("x+y="+(x+y));
}
} class B extends A{
}
class run{
public static void main(String[] args)
{
A aa=new A();
B bb=new B();
bb.x=10;
bb.y=20;
bb.num();
} }
staticbody
objectA
num()
objectB
B
class B{
int x,y;
public void num()
}
System.out.println("x+y="+x+y);
{
x+y=30
10. class nabil{
int x=10;
int y=20;
void show()
{
System.out.println("x="+x+"n"+"y="+y);
}
}
class dawod extends nabil{
public dawod(){
++x;
--y;
}
public static void main(String[] args) {
dawod d=new dawod();
d.show();
}
}
x=11
y=19
Output
14. class A}
void sum(int x,int y)}
System.out.println("in class A: x+y="+(x+y));
}
}
class B extends A}
void sum(int x,int y)}
System.out.println("in class B: x+y="+(x+y));
}
public static void main(String[] args) }
B oo=new B();
oo.sum(10,20);
}
}
in class B: x+y=30
Boverriding(
overriding
Write java program that use overriding method in two classes one of them is A and the other is B
inhrites A ? (use two methods)
18. import javax.swing.*;
class mohammed extends JPanel}
JLabel j1,j2;
JTextField t1,t2;
JButton b1;
JPanel
public mohammed((}
setLayout(null(;
j1=new JLabel("Name"(;
j1.setBounds(10,20,40,25(;
add(j1(;
t1=new JTextField((;
t1.setBounds(60,20,200,25(;
add(t1(;
j2=new JLabel("ID"(;
j2.setBounds(20,50,40,25(;
add(j2(;
t2=new JTextField((;
t2.setBounds(60,50,25,25(;
add(t2(;
b1=new JButton("ok"(;
b1.setBounds(110,100,80,30(;
add(b1(;
}
labelname
Name
labelpanel
j1.setBounds(10,20,40,25(;
(0,0(
(10,20(
40
25
labelpanel
ID
ok
19. ID
ok
name
public static void main(String[] avgs(
}
mohammed m=new mohammed((;
JFrame f=new JFrame("fffffff"(;
f.setVisible(true(;
f.setSize(300,250(;
f.setContentPane(m(;
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE(;
}
}
mohammed
f.setSize(width,height(;