Hiding Member Variables in Java Example

We can access the hidden member variable super class with super keyword. 🙂 Example: public class Student { public int mark = 10; } // Demonstrating super in Hiding Member Variables in CodeParent.com public class Marks extends Student{ public int mark = 80; void showMarks() { System.out.println(“The Name is :”+super.mark); System.out.println(“The Mark is :”+mark); } } public class Result { public static void main(String[] args) { // TODO Auto-generated method stub Marks m = new Marks(); m.showMarks(); } } Output: The Name is :10 The…

Continue reading »

The super Keyword in Java

Usages of super keyword: It calls the constructor of super class. Access a member of a super class that has been hidden by a member of the class. Syntax for calling base class Constructor, super(arg_list); super() should be the first statement in derived class constructor. Example: //Demonstrating super in CodeParent.com public class First { String Name; String Result; First(String n, String r) { Name = n; Result = r; } void showResult() { System.out.println(“Name is :” + Name); System.out.println(“Result is :” + Result); } }…

Continue reading »