The Artima Developer Community
Sponsored Link

Java Buzz Forum
Super keyword java programs for interview for freshers and experienced

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Super keyword java programs for interview for freshers and experienced Posted: Jul 16, 2016 7:45 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Super keyword java programs for interview for freshers and experienced
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  • 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. }


Click for Output



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


super keyword java interview programs for freshers


Click for Output


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. }


Click for Output


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. }



Click for Output

Read: Super keyword java programs for interview for freshers and experienced

Topic: OpenStack-related business models to exceed $4bn by 2019, 451 Research Previous Topic   Next Topic Topic: JavaFX Real-World Apps: SkedPal

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use