Fazrin/Core Java Interview Questions and Answers

Created Thu, 13 Oct 2022 19:59:57 +0530 Modified Fri, 22 Dec 2023 18:51:58 +0000
141 Words

//inside class double test = Math.PI * 5;

//no need to refer class now double test = PI * 5;

public class SuperClass {

public SuperClass(){
}

public SuperClass(int i){}

public void test(){
	System.out.println("super class test method");
}

}

public class ChildClass extends SuperClass {

public ChildClass(String str){
	//access super class constructor with super keyword
	super();
	
	//access child class method
	test();
	
	//use super to access super class method
	super.test();
}

@Override
public void test(){
	System.out.println("child class test method");
}

}

if(str instanceof String){
	System.out.println("String value:"+str);
}
	
if(str instanceof Integer){
	System.out.println("Integer value:"+str);
}

}

public class Test {

public static String toString(){
	System.out.println("Test toString called");
	return "";
}

public static void main(String args[]){
	System.out.println(toString());
}

}

public class Test {

public static String foo(){
	System.out.println("Test foo called");
	return "";
}

public static void main(String args[]){
	Test obj = null;
	System.out.println(obj.foo());
}

}