• Lets see some interesting java programs on super keyword.
  • Basically super keyword used to refer super class methods and variables. So now let us see how super will work in some scenarios. lets practice.
  • Try to answer below java programming interview questions for beginners. 
  • Java programs asked in technical interview for freshers and experienced.




Program #1: What will be the output of below java program

  1. package com.superkeywordinjava;
  2.  public Class SuperDemo{ 
  3.  
  4. int a,b;
  5.  
  6. }

  1. package com.superkeywordinjava;
  2. public Class Subdemo extends SuperDemo{ 
  3. int a,b;
  4. void disply(){

  5. super.a=10;
  6. super.b=20;
  7.  
  8. System.out.println(a);
  9. System.out.println(b);
  10. System.out.println(super.a);
  11. System.out.println(super.b);
  12.  
  13. }
  14.  
  15. public static void main (String args[]) {
  16.  Subdemo obj= new Subdemo();
  17.  
  18. obj.a=1;
  19. obj.b=2;
  20.  
  21. obj.disply();
  22.  

  23.  
  24. }
  25. }






Program #2: What will be the output of below java program


super keyword java interview programs for freshers





Program #3: Basic java programs for interview on super keyword

  1. package com.superinterviewprograms;
  2. public Class SuperDemo{ 
  3.  
  4. int a,b;
  5.  
  6. SuperDemo(int x, int y){
  7.  a=x;
  8. b=y
  9. System.out.println("Super class constructor called ");
  10.  
  11.  
  12. }

  1. package com.superinterviewprograms;
  2.  
  3. public Class Subdemo extends SuperDemo{ 
  4.  
  5. int a,b;
  6.  
  7. SubDemo(int x, int y){
  8. super(10,20);
  9.  a=x;
  10. b=y
  11. System.out.println("Sub class constructor called ");
  12. }
  13.  
  14. public static void main (String args[]) {
  15.  Subdemo obj= new Subdemo(1,2);

  16.  
  17. }
  18. }





Program #4: Java interview Program on super keyword

  • What will happen if our class constructor having super() call but our class not extending any class.

  1. package com.superinterviewprograms;
  2.  
  3. public Class Sample{ 
  4.  
  5. Sample(){
  6. super();
  7. System.out.println("Sample class constructor called "); 
  8.  
  9. }
  10.  
  11. public static void main (String args[]) {
  12.  
  13.  Sample obj= new Sample();
  14.  
  15. }
  16. }





Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu