Paste Search Dynamic
String getName
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class A {
  8.         private string name = "Abhinav";
  9.         public A(string nam) {
  10.                 //name = nam;
  11.         }
  12.  
  13.         public string getName() {
  14.                 return name;
  15.         }
  16. }
  17.  
  18. class B extends A {
  19.         string surname;
  20.         public B(string name) {
  21.                 super("Ashwaq");
  22.                 surname = name;
  23.         }
  24. }
  25.  
  26. /* Name of the class has to be "Main" only if the class is public. */
  27. class Main
  28. {
  29.         public static void main (string[] args) throws java.lang.exception
  30.         {
  31.                 B b = new B("Singh");
  32.                 system.out.println(b.surname);
  33.                 system.out.println(b.getName());
  34.         }
  35. }
  36.  
Parsed in 0.023 seconds