Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package keyword;
- public class keywordFinal
- {
- public static void main(String[] args)
- {
- ClassA clA = new ClassA(20, 90);
- clA.dispFinal();
- clA.dispMyInt();
- CLassB clB = new CLassB();
- clB.setMyInt(50);
- clB.dispMyInt();
- }
- }
- // OUTPUT
- //The value of final variable : 20
- //The value MyInt : 90
- //The value of MyInt for Class B : 50
- package keyword;
- class ClassA
- {
- final int finInteger;
- protected int myInt;
- public ClassA(int x, int y)
- {
- finInteger = x; // initialize for only one time
- myInt = y;
- }
- public ClassA()
- {
- this(0, 0);
- }
- final public void dispFinal() // final methods can not be overriden
- {
- System.out.println("The value of final variable : "+ finInteger);
- }
- public void dispMyInt()
- {
- System.out.println("The value MyInt : "+ myInt);
- }
- }
- final class CLassB extends ClassA // final class will not be extended
- {
- protected int myInt;
- public void setMyInt(int x)
- {
- myInt = x;
- }
- public void dispMyInt() // overriden method
- {
- System.out.println("The value of MyInt for Class B : "+ myInt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement