• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is going on in this code  RSS feed

 
Vikas J Yadav
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package com.infy.cert;

public class Chapter2 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SubClass sc=new SubClass();
}
}
class SuperClass{
public SuperClass(){
System.out.println("Superclass no-arg");
}
public SuperClass(int n){
System.out.println("Superclass arg");
}
public static int method(){
System.out.println("sup static");
return 4;
}
}
class SubClass extends SuperClass{
public SubClass(int n){
System.out.println("Subclass arg");
}
public SubClass(){
super(method());
System.out.println("Subclass no-arg");
}
public static int method(){
System.out.println("sub static");
return 5;
}
}

Produced Output as
sub static
Superclass arg
Subclass no-arg

I have written a code to call SuperClass satic method; I know that SuperClass static methods cannot be overriden but what happens with this line, super(method()); of code
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Please UseCodeTags and properly indent your code - that will make it much easier to read on the forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!