programming languages Online Quiz - 32
Description: programming languages Online Quiz - 32 | |
Number of Questions: 20 | |
Created by: Aliensbrain Bot | |
Tags: programming languages |
Can a subclass access the private values of the super class
given x = y--; What will be true after execution?
What is the output for the below code ? public class Test { public static void main(String... args) { Pattern p = Pattern.compile("a{3}b?c*"); Matcher m = p.matcher("aaab"); boolean b = m.matches(); System.out.println(b); } }
What is the output for the below code ? public class Test extends Thread{ static String sName = "good"; public static void main(String argv[]){ Test t = new Test(); t.nameTest(sName); System.out.println(sName); } public void nameTest(String sName){ sName = sName + " idea "; start(); } public void run(){ for(int i=0;i < 4; i++){ sName = sName + " " + i; } } }
What is the output for the below code ? public class A {} public class B implements Serializable { A a = new A(); public static void main(String... args){ B b = new B(); try{ FileOutputStream fs = new FileOutputStream("b.ser"); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(b); os.close(); }catch(Exception e){ e.printStackTrace(); } } }
What is the output for the below code running in the same JVM? public class A implements Serializable { transient int a = 7; static int b = 9; } public class B implements Serializable { public static void main(String... args){ A a = new A(); try { ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream("test.ser")); os.writeObject(a); os. close(); System.out.print( + + a.b + " "); ObjectInputStream is = new ObjectInputStream(new FileInputStream("test.ser")); A s2 = (A)is.readObject(); is.close(); System.out.println(s2.a + " " + s2.b); } catch (Exception x) { x.printStackTrace(); } } }
What is the output for the below code ? public enum Test { BREAKFAST(7, 30), LUNCH(12, 15), DINNER(19, 45); private int hh; private int mm; Test(int hh, int mm) { assert (hh >= 0 && hh <= 23) : "Illegal hour."; assert (mm >= 0 && mm <= 59) : "Illegal mins."; this.hh = hh; this.mm = mm; } public int getHour() { return hh; } public int getMins() { return mm; } public static void main(String args[]){ Test t = new BREAKFAST; System.out.println(t.getHour() +":"+t.getMins()); } }
What is the output for the below code ? public class A { public A() { System.out.println("A"); } } public class B extends A implements Serializable { public B() { System.out.println("B"); } } public class Test { public static void main(String... args) throws Exception { B b = new B(); ObjectOutputStream save = new ObjectOutputStream(new FileOutputStream("datafile")); save.writeObject(b); save.flush(); ObjectInputStream restore = new ObjectInputStream(new FileInputStream("datafile")); B z = (B) restore.readObject(); } }
. What is the output for the below code ? public class Test{ public static void main(String argv[]){ Test1 pm1 = new Test1("One"); pm1.run(); Test1 pm2 = new Test1("Two"); pm2.run(); } } class Test1 extends Thread{ private String sTname=""; Test1(String s){ sTname = s; } public void run(){ for(int i =0; i < 2 ; i++){ try{ sleep(1000); }catch(InterruptedException e){} yield(); System.out.println(sTname); } } }
What is the output for the below code ? public class Test extends Thread{ public static void main(String argv[]){ Test b = new Test(); b.start(); } public void run(){ System.out.println("Running"); } }
What is the output for the below code ? public class Tech { public void tech() { System.out.println("Tech"); } } public class Atech { Tech a = new Tech() { public void tech() { System.out.println("anonymous tech"); } }; public void dothis() { a.tech(); } public static void main(String... args){ Atech atech = new Atech(); atech.dothis(); }
What is the output for the below code ? public class Outer { private String x = "Outer variable"; void doStuff() { String z = "local variable"; class Inner { public void seeOuter() { System.out.println("Outer x is " + x); System.out.println("Local variable z is " + z); } } } }
What is the output for the below code ? public class Test { public static void main(String... args) { for(int i = 2; i < 4; i++) for(int j = 2; j < 4; j++) assert i!=j : i; } }
What is the output for the below code ? public class NameBean { private String str; NameBean(String str ){ this.str = str; } public String toString() { return str; } } import java.util.HashSet; public class CollClient { public static void main(String ... sss) { HashSet myMap = new HashSet(); String s1 = new String("das"); String s2 = new String("das"); NameBean s3 = new NameBean("abcdef"); NameBean s4 = new NameBean("abcdef"); myMap.add(s1); myMap.add(s2); myMap.add(s3); myMap.add(s4); System.out.println(myMap); } }
Synchronized resizable-array implementation of the List interface is _____________?
What is the output for the below code ? public class Test { public static void main(String argv[]){ ArrayList list = new ArrayList(); ArrayList listStr = list; ArrayList listBuf = list; listStr.add(0, "Hello"); StringBuffer buff = listBuf.get(0); System.out.println(buff.toString()); } }
What is the output for the below code ? import java.util.LinkedList; import java.util.Queue; public class Test { public static void main(String... args) { Queue q = new LinkedList(); q.add("newyork"); q.add("ca"); q.add("texas"); show(q); } public static void show(Queue q) { q.add(new Integer(11)); while (!q.isEmpty ( ) ) System.out.print(q.poll() + " "); } }
What are the new features added to Java 1.5?
Key word "transient" is used so that the state of the object is not saved... (T/F)
Can you call one constructor from another if a class has multiple constructors