forked from adityabiswal2147207/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinalin.java
More file actions
71 lines (54 loc) · 1.42 KB
/
finalin.java
File metadata and controls
71 lines (54 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//Coded by:- Aditya Biswal
//java program that will be illustrating the use of final with the concept of inheritance
//importing java libraries:-->
import java.lang.String;
import java.io.*;
//making a base class
abstract class details
{
private String name;
private String age;
private String address;
//making a parameterized constructor:-->
public details(String name, String age, String address)
{
this.name = name;
this.age = age;
this.address = address;
}
//now getting the name as final so any class extending details cannot override it
public final String getName()
{
return name;
}
public final String getAge()
{
return age;
}
public final String getAddress()
{
return address;
}
abstract String getDetails();
}
//creating a derived class now
class person extends details
{
public void per_det(String name, String age, String address)
{
//calling detail class constructor
Super(name,age,address);
}
final String getDetails()
{
return this.getName();
return this.getAge();
return this.getAddress();
}
}
public class finalin {
details obj1 = new person("Aditya","24","Bangalore");
System.out.println("Name: " + obj1.getName());
System.out.println("Age: " + obj1.getAge());
System.out.println("Address: " + obj1.getAddress());
}