Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
66 lines (52 loc) · 1.65 KB

File metadata and controls

66 lines (52 loc) · 1.65 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package chapter11;
/* J11_00.java */
/* Illustrating Effects of Inheritance */
class Student extends Object{ // Base class
int Roll; // friendly by default
String Name= new String(); // friendly by default
}
class Result extends Student {
float Mark;
void setData() {
Roll = 101; // Accessing inherited member
Name = "Masud"; // Accessing inherited member
Mark = 75.50f; // Accessing own member
}
void display() {
System.out.println("Roll is : " +Roll);
// Accessing inherited member
System.out.println("Name is : " +Name);
// Accessing inherited member
System.out.println("Mark is : " +Mark) ;
// Accessing own member
}
}
public class J11_00{
public static void main(String... args) {
Student S1 = new Student();
// Creating Base-class object
System.out.println("Accessing Base-Class Variables.....");
S1.Name = "Mosaddek Mahdi";
S1.Roll = 101;
System.out.println("S1.Name : " + S1.Name);
System.out.println("S1.Roll : " + S1.Roll);
System.out.println();
System.out.println("Accessing Derived-Class Variables.....");
Result R1 = new Result();
// Creating Derived-class object
R1.Name = "Muhaimin Munim";
R1.Roll = 102;
R1.Mark = 99.0f;
System.out.println("R1.Name : " + R1.Name);
System.out.println("R1.Roll : " + R1.Roll);
System.out.println("R1.Name : " + R1.Name);
System.out.println("\nAccessing Derived-Class Methods.....");
R1.setData();
R1.display();
System.out.println();
//S1.setData(); // Shows following Compile-time Error
// The method setData() is undefined for the type Student
// S1.display(); // Shows following Compile-time Error
// The method display() is undefined for the type Student
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.